I'm trying to upload a 'txt' file to dropbox with python API. After looking everywhere I know I found nothing that works, or I just don't understand how to make it work.
with open('Hello.txt') as f:
dbx.files_upload(f,'/PythonClass/data_src')
I have also tried this:
with open('Hello.txt') as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
and this:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
I'm getting an error:
Traceback (most recent call last):
File "c:\Users\User\Desktop\pytask\classprojectdropbox", line 46, in <module>
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\dropbox\base.py", line 2931, in files_upload
r = self.request(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\dropbox\dropbox_client.py", line 348, in request
raise ApiError(res.request_id,
dropbox.exceptions.ApiError: ApiError('2d7014d399964557a8658a49ae90ef75', UploadError('path', UploadWriteFailed(reason=WriteError('conflict', WriteConflictError('folder', None)), upload_session_id='pid_upload_session:TOKEN')))
CodePudding user response:
The f
parameter for files_upload
expects bytes
, so you should make sure you both open the file as binary ("rb"
) and then read
the data out, like this:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))