作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Python 类中,我有一个函数可以生成 csv 文件,将该文件上传到 Dropbox,然后尝试生成指向已上传文件的共享链接,过期时间为 5 分钟。
我正在尝试遵循提供的示例 here ;我的代码如下:
# Helper upload function
def upload_file(self, dbx, file_from, file_to):
"""upload a file to Dropbox using API v2
"""
with open(file_from, 'rb') as f:
dbx.files_upload(f.read(), file_to, mode=WriteMode('overwrite'))
# Target function
def generate_expiring_dropbox_link(self, local_path, dbx_path):
dbx = dropbox.Dropbox(self.temp_dropbox_token)
expires = datetime.datetime.now() + datetime.timedelta(minutes=5)
requested_visibility = dropbox.sharing.RequestedVisibility.team_only
desired_shared_link_settings = dropbox.sharing.SharedLinkSettings(requested_visibility=requested_visibility,
expires=expires)
# open the file and upload it
self.upload_file(dbx, local_path, dbx_path)
shared_link_metadata = dbx.sharing_create_shared_link_with_settings(path=dbx_path, settings=desired_shared_link_settings)
return shared_link_metadata
我一直收到与共享链接设置相关的 API 错误:
dropbox.exceptions.ApiError: ApiError('************', CreateSharedLinkWithSettingsError('settings_error', SharedLinkSettingsError('invalid_settings', None)))
我找不到太多这方面的文档;有人遇到过/找到解决方案吗?只是想知道是否有基于 python 的修复,或者包装 HTTP 请求是否是更好的选择。我使用的是 Python 3.6 和 Dropbox 8.9.0。
最佳答案
Dropbox API 需要 UTC 时间。您提供的本地时间可以是相对于 UTC 时间的过去时间。如果是这样,API 将拒绝设置,因为过期时间不能是过去的。
所以,而不是:
expires = datetime.datetime.now() + datetime.timedelta(minutes=5)
做:
expires = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
关于Python Dropbox API v2 : error when passing SharedLinkSettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50512663/
在我的 Python 类中,我有一个函数可以生成 csv 文件,将该文件上传到 Dropbox,然后尝试生成指向已上传文件的共享链接,过期时间为 5 分钟。 我正在尝试遵循提供的示例 here ;我的
我是一名优秀的程序员,十分优秀!