使用Python中的Dropbox API v2覆盖文件

Stu*_*son 5 python python-3.x dropbox-api

我试图用Python 3.4覆盖Dropbox上的文件,但无法弄清楚如何做到这一点.如果该文件不存在,dbx.files_upload(data, '/file.py')则按预期创建该文件.

但是如果文件存在,我想覆盖它.我试过了

dbx.files_upload(data, '/file.py', mode=WriteMode('overwrite'))
Run Code Online (Sandbox Code Playgroud)

这使

NameError: name 'WriteMode' is not defined
Run Code Online (Sandbox Code Playgroud)

我试过了

dbx.files_upload(data, '/iot_main.py', overwrite=True)
Run Code Online (Sandbox Code Playgroud)

这使

TypeError: files_upload() got an unexpected keyword argument 'overwrite'
Run Code Online (Sandbox Code Playgroud)

我觉得好像我错过了一些明显的东西,但谷歌搜索的答案并没有多大帮助......

谢谢.

sil*_*fox 16

Dropbox SDK示例中尝试这个.

dbx.files_upload(data, '/file.py', mode=dropbox.files.WriteMode.overwrite)
Run Code Online (Sandbox Code Playgroud)


小智 6

只需将其添加到您的文件中即可。

from dropbox.files import WriteMode
Run Code Online (Sandbox Code Playgroud)