gpt4 book ai didi

python - PycURL RESUME_FROM

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:59 24 4
gpt4 key购买 nike

我似乎无法让 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()

最佳答案

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

关于python - PycURL RESUME_FROM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3027677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com