Dropbox / delta ignores cursor

I am trying to list files on Dropbox for Business .

The Dropbox Python SDK does not support Dropbox for Business, so I use Python to send POST requests directly to https://api.dropbox.com/1/delta .

The next function repeats calls to Dropbox / delta, each of which should get a list of files along with a cursor.

Then a new cursor is sent with the next request to get the next list of files.

BUT he always gets the same list. It's like Dropbox is ignoring the cursor I am sending.

How can I get Dropbox to recognize the cursor?

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

      

The complete code is at https://github.com/blokeley/dfb/blob/master/dfb.py

My code is very similar to the official Dropbox blog example , except that they use the SDK, which I can't because I'm on Dropbox for Business and send additional headers.

Any help would be greatly appreciated.

+3


source to share


1 answer


It looks like you are sending a JSON encoded body instead of a form encoded body.

I think just change json

to data

on this line:

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

      



EDIT Here's the complete working code:

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']

      

+1


source







All Articles