gpt4 book ai didi

python - Dropbox/delta 忽略光标

转载 作者:行者123 更新时间:2023-11-28 18:37:43 24 4
gpt4 key购买 nike

我正在尝试列出 Dropbox for Business 上的文件.

Dropbox Python SDK不支持 Dropbox for Business,所以我使用 Python requests module将 POST 请求发送到 https://api.dropbox.com/1/delta直接。

在下面的函数中,重复调用了 Dropbox/delta,每个调用都应该得到一个文件列表和一个光标。

然后新游标随下一个请求一起发送,以获取下一个文件列表。

但它总是得到相同的列表。就好像 Dropbox 忽略了我发送的光标。

如何让 Dropbox 识别光标?

def get_paths(headers, paths, member_id, response=None):
"""Add eligible file paths to the list of paths.

paths is a Queue of files to download later
member_id is the Dropbox member id
response is an example response payload for unit testing
"""

headers['X-Dropbox-Perform-As-Team-Member'] = member_id
url = 'https://api.dropbox.com/1/delta'
has_more = True
post_data = {}

while has_more:
# If ready-made response is not supplied, poll Dropbox
if response is None:
logging.debug('Requesting delta with {}'.format(post_data))
r = requests.post(url, headers=headers, json=post_data)
# Raise an exception if status is not OK
r.raise_for_status()

response = r.json()

# Set cursor in the POST data for the next request
# FIXME: fix cursor setting
post_data['cursor'] = response['cursor']

# Iterate items for possible adding to file list [removed from example]

# Stop looping if no more items are available
has_more = response['has_more']

# Clear the response
response = None

完整代码位于 https://github.com/blokeley/dfb/blob/master/dfb.py

我的代码看起来与 official Dropbox blog example 非常相似,除了他们使用我不能使用的 SDK,因为我在 Dropbox for Business 上并且必须发送额外的 header 。

如有任何帮助,将不胜感激

最佳答案

看起来您发送的是 JSON 编码的正文而不是表单编码的正文。

我认为只需将这一行中的 json 更改为 data 即可:

r = requests.post(url, headers=headers, data=post_data)

编辑这是一些完整的工作代码:

import requests

access_token = '<REDACTED>'
member_id = '<REDACTED>'

has_more = True
params = {}
while has_more:
response = requests.post('https://api.dropbox.com/1/delta', data=params, headers={
'Authorization': 'Bearer ' + access_token,
'X-Dropbox-Perform-As-Team-Member': member_id
}).json()

for entry in response['entries']:
print entry[0]

has_more = response['has_more']
params['cursor'] = response['cursor']

关于python - Dropbox/delta 忽略光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30820194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com