【发布时间】:2013-06-19 03:28:55
【问题描述】:
我在使用 python 下载管理器时遇到了问题。我已经尝试过仅使用 wget 下载并且它有效。我还创建了我的 wxpython 界面。但我现在的问题是如何将两者结合起来?我如何将 wget 下载代码添加到我的 wxpython 界面并使其工作?是否可以将 wget 与 python 结合起来提供下载管理器,例如 winwget 或 visualwget?
import os
from ftplib import FTP
ftp = FTP("ftpsite","username", "password")
ftp.login()
ftp.retrlines("LIST")
ftp.cwd("folderOne")
ftp.cwd("subFolder")
listing = []
ftp.retrlines("LIST", listing.append)
words = listing[0].split(None, 8)
filename = words[-1].lstrip()
#download the file
local_filename = os.path.join(r"C:\example", file)
lf = open(local_filename, "wb")
ftp.retrbinary("RETR " + filename, lf.write, 8*1024)
lf.close()
我试过这个代码,它来自你的博客。但它说,
Traceback (most recent call last):
File "directory", line 4, in <module>
ftp = FTP("ftp://samoa.gsfc.nasa.gov/site/", "user", "password")
File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11004] getaddrinfo failed
代码有什么问题?
【问题讨论】:
-
看看
subprocess模块。你确定你真的需要 wget 吗?为什么不用纯 Python 和urllib2或requests来实现呢? -
谢谢!但是我也可以在 WxPython 中使用 urllib2 或 requests 吗?因为我不知道如何使用它。 Wget 具有自动下载功能,这就是我在下载管理器中所需要的。
-
反过来想。您需要一个下载功能,而
wget恰好可以做到这一点。 WxPython 几乎可以使用任何东西。 -
有没有使用 Wget 和 Python 创建的下载管理器?我不知道如何安装和使用 [request]?
-
你为什么使用 Python 2.5?升级到 2.7.5。
标签: python wxpython wget download