0

I am building a test upload api to check dropbox to build final project but I am getting this error when i run python file in cmd:

Traceback (most recent call last):
  File "C:\Users\sufiy\Desktop\test.py", line 7, in <module>
    dbx.files_upload(file_contents, '/testdropbox.txt', mode=dropbox.files.WriteMode.overwrite)
  File "C:\Users\sufiy\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\base.py", line 3210, in files_upload
    r = self.request(
        ^^^^^^^^^^^^^
  File "C:\Users\sufiy\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\dropbox_client.py", line 326, in request
    res = self.request_json_string_with_retry(host,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sufiy\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\dropbox_client.py", line 476, in request_json_string_with_retry
    return self.request_json_string(host,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sufiy\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\dropbox_client.py", line 538, in request_json_string
    raise TypeError('expected request_binary as binary type, got %s' %
TypeError: expected request_binary as binary type, got <class 'str'>

here is my code:

import dropbox

dbx = dropbox.Dropbox('my api key')
with open('testdropbox.txt', 'r') as f:
     file_contents = f.read()   
dbx.files_upload(file_contents, '/testdropbox.txt', mode=dropbox.files.WriteMode('overwrite'))

I tried to build a program that overwrite txt file every minute and I want it to work so I can schedule this by using windows task schedule

  • Open the file in 'rb' mode to get bytes instead of str: [Difference between parsing a text file in r and rb mode](https://stackoverflow.com/questions/9644110/difference-between-parsing-a-text-file-in-r-and-rb-mode) – mkrieger1 Dec 22 '22 at 21:49
  • Welcome to Stack Overflow! Please take the [tour]. SO is a Q&A site, so what's your question? Like, what help do you need exactly? To start do you understand what the error message is saying? I haven't used this package myself, but it sounds like it's looking for a `bytes` object, not a string. For more tips, see [ask]. You can [edit] to clarify. – wjandrea Dec 22 '22 at 21:49
  • Also, maybe this is beside the point, but that code doesn't match that traceback. The `dropbox.files.WriteMode...` is different. – wjandrea Dec 22 '22 at 21:50
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 22 '22 at 21:58

0 Answers0