[英]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'))
我收到一个错误:
raise TypeError('expected request_binary as binary type, got %s' %
TypeError: expected request_binary as binary type, got <class '_io.TextIOWrapper'>
files_upload
的f
参数需要bytes
,因此您应该确保以二进制文件 ( "rb"
) 打开文件,然后read
数据,如下所示:
with open('Hello.txt', "rb") as f:
dbx.files_upload(f.read(), folder_py_src, mode=WriteMode('overwrite'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.