We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

Yashik's avatar
Yashik
Explorer | Level 4
7 years ago

Dropbox v2 upload cursor offset confusion

I can only upload the first chunk only

import dropbox,requests,sys
def down(url):
dbx=dropbox.Dropbox(AccessToken)

size=25*1024*1024
a=0
i=0

params = {'':'', 'render':'download'}

r=requests.get(url,params=params,stream=True)
clen=r.headers['Content-length']

for chunk in r.iter_content(chunk_size=size):

if chunk:
i+=1
a+=len(chunk)

c=a/(1024*1024)
sys.stdout.write('\r'+str(round(c,2)))
if i==1:
strtid = dbx.files_upload_session_start(chunk)
cursor = dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=a)
commit = dropbox.files.CommitInfo(path='/source')
if (clen-a)<size:
dbx.files_upload_session_finish(chunk,cursor,commit)

else:
dbx.files_upload_session_append(chunk,cursor.session_id,cursor.offset)


url='https://downloads.sourceforge.net/project/openofficeorg.mirror/extended/iso/en/OOo_3.3.0_Win_x86_install_en-US_20110219.iso?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fopenofficeorg.mirror%2F%3Fsource%3Ddirectory&ts=1533004315&use_mirror=excellmedia'
down(url)


And I got a error

>Traceback (most recent call last):
> File "/home/google2drive/mysite/templates/u.py", line 38, in <module>
> down(url)
> File "/home/google2drive/mysite/templates/u.py", line 32, in down
> dbx.files_upload_session_append(chunk,cursor.session_id,cursor.offset)
> File "/home/google2drive/.local/lib/python3.6/site-packages/dropbox/base.py", line 2242, in files_upload_session_append
> f,
> File "/home/google2drive/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 296, in request
> user_message_locale)
>dropbox.exceptions.ApiError: >ApiError('0e6a9a0abf5e491efe40d71e4c6cdb76', >UploadSessionLookupError('incorrect_offset', >UploadSessionOffsetError(correct_offset=52428800)))
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    [Cross-linking for reference: https://stackoverflow.com/questions/51606801/python3-dropbox-uploading-error-using-api-v2 ]

     

    That error indicates that you're supplying an incorrect offset value for this upload session when uploading a chunk of data. The error includes the correct value, but you'll need to debug your code to see why you're not sending it in the first place. (I don't see where you update the offset value in your code, for example.)

     

    There's a basic example of using upload sessions with the Python SDK here:

     

    https://stackoverflow.com/a/43724479/1305693

    • Yashik's avatar
      Yashik
      Explorer | Level 4
      I have the variable `a` for offset.
      Now i'm getting UploadSessionError('path',WriteError('conflict',WriteConflictError('file',None))))
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        A 'path/conflict/file' error indicates that the upload failed because there is already a file at the specified path.

         

        You should instead specify a different path, or supply a different WriteMode to to files_upload_session_finish in the CommitInfo to automatically handle the conflict.