【发布时间】:2019-10-02 02:59:32
【问题描述】:
如何使用 Python 将 csv 文件上传到 Dropbox
我尝试了下面这篇文章中的所有示例,但都不起作用
upload file to my dropbox from python script
我收到错误:
FileNotFoundError: [Errno 2] 没有这样的文件或目录:'User\pb\Automation\test.csv'
- 我的用户名:pb
- 文件夹名称:自动化
- 文件名:test.csv
import pathlib
import dropbox
import re
# the source file
folder = pathlib.Path("User/pb/Automation") # located in folder
filename = "test.csv" # file name
filepath = folder / filename # path object, defining the file
# target location in Dropbox
target = "Automation" # the target folder
targetfile = target + filename # the target path and file name
# Create a dropbox object using an API v2 key
token = ""
d = dropbox.Dropbox(token)
# open the file and upload it
with filepath.open("rb") as f:
# upload gives you metadata about the file
# we want to overwite any previous version of the file
meta = d.files_upload(f.read(), targetfile, mode=dropbox.files.WriteMode("overwrite"))
# create a shared link
link = d.sharing_create_shared_link(targetfile)
# url which can be shared
url = link.url
# link which directly downloads by replacing ?dl=0 with ?dl=1
dl_url = re.sub(r"\?dl\=0", "?dl=1", url)
print (dl_url)
FileNotFoundError: [Errno 2] No such file or directory: 'User\\pb\\Automation\\test.csv'
【问题讨论】:
标签: python file-upload dropbox-api