问题描述
我正在使用python请求库以多处理方式从“ onionurl”下载文件,以从tor服务下载许多文件。
这就是代码背后的原因。
但是,下载这些文件时,它们每隔一两分钟就会切出。由于流中的下载失败,因此不会给出任何错误,但会返回“关闭文本文件”。这意味着不可能下载这些洋葱服务器上托管的文件,这些文件每个都有数百GB。
对于解决此问题的任何帮助,将不胜感激。
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
#print(onionurlforrequest)
url = onionurl
try:
if not os.path.isdir(foldername):
os.makedirs(foldername)
# download the body of response by chunk,not immediately
with session.get(url,stream=True,verify=False,timeout=1000000) as response:
# get the total file size
file_size = int(response.headers.get("Content-Length",0))
print(file_size)
# get the file name
filename = dataloc
with open(filename,"wb") as text_file:
for chunk in response.iter_content(chunk_size=1024):
text_file.write(chunk)
if (file_size > 1000000):
filesizemb = file_size / 1000000
else:
filesizemb = 1
print("closing text file")
text_file.close()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)