I am trying to use the official dropbox API python implementation to do range download.
My request looks good because I can don't have any error, but when the answer is parsed I get this error :
ERROR: [206] Error parsing response body or headers: Body - 'PK\x03\x04\x14\x00\x08\x00\x08\x00\xac\x82\xf4B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12 Headers - {'content-length': '25600001', 'accept-ranges': 'bytes', 'x-dropbox-metadata': '{"revision": 3, "rev": "31b5076b9", "thumb_exists": false, "bytes": 41349982, "modified": "Sat, 28 Dec 2013 00:48:54 +0000", "client_mtime": "Sat, 28 Dec 2013 00:48:54 +0000", "path": "/SUPERHOT-LINUX.zip", "is_dir": false, "icon": "page_white_compressed", "root": "dropbox", "mime_type": "application/zip", "size": "39.4 MB"}', 'x-server-response-time': '551', 'connection': 'keep-alive', 'server': 'nginx', 'content-range': 'bytes 0-25600000/41349982', 'etag': '3n', 'x-requestid': 'a55723c8c4bef7d24246a8047b76858f', 'x-dropbox-request-id': a781c2d352d3e15426cb9b3902325158', 'pragma': 'public', 'cache-control': 'max-age=0', 'date': 'Sat, 28 Dec 2013 03:12:17 GMT', 'content-type': 'application/zip'}
My request is built using :
url, params, headers = self.client.request("/files/dropbox/"+fname, {}, method='GET', content_server=True)
headers['Range'] = 'bytes=' + str(startchunk)+"-"+str(endchunk)
f = self.client.rest_client.request("GET", url, headers=headers, raw_response=True)
Do you know why I get this error?
Thank you in advance
I think you want raw_response=True
(not False
). I believe that with it set to False
, the library tries to parse the response as JSON.
EDIT: Second answer is better, now that I've tried this myself. :-) raw_response
should definitely be True
, but the library doesn't handle the HTTP status code 206 (Partial Content). I'll file a bug internally to get this addressed, but if you want a quick patch, line 226 of rest.py
in the latest (2.0.0) release should look like this right now:
if r.status != 200:
Change it instead to this:
if r.status != 200 and r.status != 206:
After making that change, I can run code very similar to yours and properly get back just a portion of a file.