【问题标题】:PycURL RESUME_FROMPycURL RESUME_FROM
【发布时间】:2010-06-12 05:55:02
【问题描述】:

我似乎无法让 RESUME_FROM 选项起作用。这是我一直在测试的一些示例代码:

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()

【问题讨论】:

    标签: python pycurl resume-download


    【解决方案1】:

    它实际上正在正常恢复,但是它似乎又从头开始了,因为 os.path.getsize(filename) 的长度没有添加到进度函数中的现有值中。只是一个小错误! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2014-06-26
      相关资源
      最近更新 更多