Python3:使用API​​ v2的Dropbox上传错误

时间:2018-07-31 06:33:32

标签: python-3.x dropbox

我在上传时遇到问题,只有第一个块正在上传,然后出现错误。 这是代码

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)

错误:

  

回溯(最近通话最近):    在第38行的文件“ /home/google2drive/mysite/templates/u.py”      下(url)    文件“ /home/google2drive/mysite/templates/u.py”,第32行,向下      dbx.files_upload_session_append(chunk,cursor.session_id,cursor.offset)    在files_upload_session_append中的文件“ /home/google2drive/.local/lib/python3.6/site-packages/dropbox/base.py”第2242行      F,    请求中的文件“ /home/google2drive/.local/lib/python3.6/site-packages/dropbox/dropbox.py”,第296行      user_message_locale)   dropbox.exceptions.ApiError:ApiError('0e6a9a0abf5e491efe40d71e4c6cdb76',UploadSessionLookupError('incorrect_offset',UploadSessionOffsetError(correct_offset = 52428800)))

我该怎么办?

0 个答案:

没有答案