Dropbox api 上传文件
Dropbox api upload file
我正在尝试使用 python API 将 'txt' 文件上传到保管箱。
到处寻找后,我知道我找不到任何有用的东西,或者我只是不明白如何让它起作用。
with open('Hello.txt') as f:
dbx.files_upload(f,'/PythonClass/data_src')
我也试过这个:
with open('Hello.txt') as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
还有这个:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
我遇到一个错误:
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')))
files_upload
的 f
参数需要 bytes
,因此您应该确保以二进制 ("rb"
) 打开文件,然后 read
数据出来,像这样:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
我正在尝试使用 python API 将 'txt' 文件上传到保管箱。 到处寻找后,我知道我找不到任何有用的东西,或者我只是不明白如何让它起作用。
with open('Hello.txt') as f:
dbx.files_upload(f,'/PythonClass/data_src')
我也试过这个:
with open('Hello.txt') as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
还有这个:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
我遇到一个错误:
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')))
files_upload
的 f
参数需要 bytes
,因此您应该确保以二进制 ("rb"
) 打开文件,然后 read
数据出来,像这样:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))