Forum Discussion

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

Api v2 dropbox.files_upload_session_finish offset error

problem is the offset of files_upload_session_finish , I am using the content length for the offset but it is giving error

Code:
import dropbox,requests,sys
def down(url):

dbx=dropbox.Dropbox(AccessToken)

size=45*1024
a=0
i=0
p=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)
print('\n'+str(c)+' of '+str(clen))
if i==1:
strtid = dbx.files_upload_session_start(chunk)
cursor = dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=len(chunk))
commit = dropbox.files.CommitInfo(path='/sourttt',mode=dropbox.files.WriteMode('add'))
if ((int(clen)-p))<=size:
cur=dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=int(a))
dbx.files_upload_session_finish(chunk,cur,commit)


else:
dbx.files_upload_session_append(chunk,cursor.session_id,a)
p=a

url='https://speedtest.ftp.otenet.gr/files/test100k.db'
down(url)

Error:

dropbox.exceptions.ApiError: ('281cb346aa41adc8436f415fc4d0de0a', UploadSessionFinishError('lookup_failed', UploadSessionLookupError('incorrect_offset', UploadSessionOffsetError(correct_offset=138240))))

The content length is 100Kb(102400) but the error showing me the correct offset is 138240 and the difference between those are 35Kb . What should I do for offset value in files_upload_session_finish
?