Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Yashik
8 years agoExplorer | Level 4
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
?
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
?
2 Replies
Replies have been turned off for this discussion
- Yashik8 years agoExplorer | Level 4
Is there any way to use ```<pre>``` tag on my code so the code could be more understanding
- Greg-DB8 years ago
Dropbox Community Moderator
Yashik It looks like you had some trouble with the forum's spam filter and so made this extra thread. I'll close this one and resume the conversation on your original thread so we can keep that in one place:
And yes, the forum's "Rich Text" editor has a code button you can use to get code formatting. The button has a label like "</>".
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!