首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PycURL RESUME_FROM

PycURL RESUME_FROM
EN

Stack Overflow用户
提问于 2010-06-12 13:55:02
回答 1查看 1.2K关注 0票数 1

我似乎不能让RESUME_FROM选项工作。下面是我测试过的一些示例代码:

代码语言:javascript
复制
import os
import pycurl
import sys

def progress(total, existing, upload_t, upload_d):
    try:
        frac = float(existing)/float(total)
    except:
        frac = 0
    sys.stdout.write("\r%s %3i%%" % ("file", frac*100)  )

url = "http://launchpad.net/keryx/stable/0.92/+download/keryx_0.92.4.tar.gz"
filename = url.split("/")[-1].strip()

def test(debug_type, debug_msg):
    print "debug(%d): %s" % (debug_type, debug_msg)

c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)

# Setup writing
if os.path.exists(filename):
    f = open(filename, "ab")
    c.setopt(pycurl.RESUME_FROM, os.path.getsize(filename))
else:
    f = open(filename, "wb")
c.setopt(pycurl.WRITEDATA, f)

#c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.DEBUGFUNCTION, test)
c.setopt(pycurl.NOPROGRESS, 0)
c.setopt(pycurl.PROGRESSFUNCTION, progress)
c.perform()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-12 13:58:52

它实际上是正确恢复的,但是它似乎再次从头开始,因为在进度函数中没有将os.path.getsize(文件名)的长度添加到existing。这只是一个小错误!:)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3027677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档