Python Dropbox API v2:传递 SharedLinkSettings 时出错
Python Dropbox API v2: error when passing SharedLinkSettings
在我的 Python class 中,我有一个生成 csv 文件的功能,将此文件上传到 Dropbox,然后尝试为上传的文件生成共享 link过期时间为 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
我一直收到与共享 link 设置相关的 API 错误:
dropbox.exceptions.ApiError: ApiError('************', CreateSharedLinkWithSettingsError('settings_error', SharedLinkSettingsError('invalid_settings', None)))
我找不到很多这方面的文档;有人遇到过it/found解决办法吗?只是想知道是否有基于 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 class 中,我有一个生成 csv 文件的功能,将此文件上传到 Dropbox,然后尝试为上传的文件生成共享 link过期时间为 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
我一直收到与共享 link 设置相关的 API 错误:
dropbox.exceptions.ApiError: ApiError('************', CreateSharedLinkWithSettingsError('settings_error', SharedLinkSettingsError('invalid_settings', None)))
我找不到很多这方面的文档;有人遇到过it/found解决办法吗?只是想知道是否有基于 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)