Python和ftplib,无法登录? [英] Python and ftplib, unable to login?
本文介绍了Python和ftplib,无法登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import ftplib $ b $我学习Python,并尝试使用FTPLib模块b
connect = ftplib.FTP('ftp://www.website.com')
connect.login =('username','password')
data = []
connect.dir(data.append)
connect.quit()
for line in data:
print line
(我知道网站,用户名和密码不正确,我用我的网站数据,我不想分享)运行后收到以下错误代码:
Traceback(最近一次调用最后一次):
文件ftp.py,第3行,在< ;模块>
ftp = FTP('ftp://www.website.com')#连接到主机,默认端口
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2。 7 / ftplib.py,第120行,在__init__
self.connect(主机)
文件/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py ,第135行,连接
self.sock = socket.create_connection((self.host,self.port),self.timeout)
File/Library/Frameworks/Python.framework/Versions/ 2.7 / lib / python2.7 / socket.py,第553行,在create_connection中
为getaddrinfo(host,port,0,SOCK_STREAM)中的res:
socket.gaierror:[Errno 8] nodename nor提供的服务名称,或不知道
为了澄清,我在Mac上使用Python 2.7。我不认为我可以分享任何细节。感谢您的帮助!
解决方案
感谢Joel Hinz,我只需要从主机名中删除'ftp://'。谢谢!
I'm learning Python and I tried using the FTPLib module for Python with this code:
import ftplib
connect = ftplib.FTP('ftp://www.website.com')
connect.login = ('username', 'password')
data = []
connect.dir(data.append)
connect.quit()
for line in data:
print line
(I'm aware that the website, username and password is incorrect, I used my website data which I don't want to share) I received the following error after running the code:
Traceback (most recent call last):
File "ftp.py", line 3, in <module>
ftp = FTP('ftp://www.website.com') # connect to host, default port
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py", line 120, in __init__
self.connect(host)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py", line 135, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Just to clarify, I'm using Python 2.7 on a Mac. I don't think there is anymore details I could share. Thank you for your help!
解决方案
Thanks Joel Hinz, I just needed to remove 'ftp://' from my hostname. Thanks!
这篇关于Python和ftplib,无法登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文