python ftplib_Python和ftplib,无法登录?

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

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值