【发布时间】:2018-04-26 04:18:37
【问题描述】:
我刚刚重建了我的 Raspberry Pi,因此安装了最新版本的 Dropbox API,现在我的程序无法运行。我认为这是由于这些重大变化中的第 1 点:https://github.com/dropbox/dropbox-sdk-python/releases/tag/v7.1.0。我确信来自 SO (Dropbox API v2 - trying to upload file with files_upload() - throws TypeError) 的这个问题解决了我的问题......但作为一个新手,我无法弄清楚如何实际实现它 - 无论如何,我已经在使用 f.read()...谁能帮忙?
这是我的代码:
def DropboxUpload(file):
sourcefile = "/home/pi/Documents/iot_pm2/dropbox_transfer/" + filename
targetfile = "/" + filename
dbx = dropbox.Dropbox(cfg.dropboxtoken)
f = open(sourcefile, "r")
filecontents = f.read()
try:
dbx.files_upload(filecontents, targetfile, mode=dropbox.files.WriteMode.overwrite)
except dropbox.exceptions.ApiError as err:
print(err)
f.close()
这是错误:
Traceback (most recent call last):
File "/home/pi/Documents/iot_pm2/dropbox_uploader.py", line 20, in <module>
DropboxUpload(filename)
File "/home/pi/Documents/iot_pm2/dropbox_uploader.py", line 12, in DropboxUpload
dbx.files_upload(filecontents, targetfile, mode=dropbox.files.WriteMode.overwrite)
File "/usr/local/lib/python3.5/dist-packages/dropbox/base.py", line 2125, in files_upload
f,
File "/usr/local/lib/python3.5/dist-packages/dropbox/dropbox.py", line 272, in request
timeout=timeout)
File "/usr/local/lib/python3.5/dist-packages/dropbox/dropbox.py", line 363, in request_json_string_with_retry
timeout=timeout)
File "/usr/local/lib/python3.5/dist-packages/dropbox/dropbox.py", line 407, in request_json_string
type(request_binary))
TypeError: expected request_binary as binary type, got <class 'str'>
提前致谢。
【问题讨论】:
标签: python python-3.x dropbox-api