问题描述
我正在尝试访问开放的 DLP 测试 FTP 服务器作为练习.我不断收到 getaddrinfo 错误,但我不确定哪里出错了.我在 Windows 10 上使用 Python 2,并且已经检查过我没有使用代理.
I am trying to access the open DLP Test FTP server as a practice. I keep getting a getaddrinfo error but I am unsure of where I'm going wrong. I am using Python 2 on a Windows 10, and have already checked that I am not behind a proxy.
代码:
from ftplib import FTP ftp = FTP('ftp://ftp.dlptest.com/') ...
错误:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:Python27libftplib.py", line 120, in __init__ self.connect(host) File "C:Python27libftplib.py", line 135, in connect self.sock = socket.create_connection((self.host, self.port), self.timeout) File "C:Python27libsocket.py", line 553, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11001] getaddrinfo failed
感谢任何帮助!
推荐答案
使用
ftp = FTP('ftp.dlptest.com')
改为.
FTP 构造函数的第一个参数 是 host - 主机名 或 IP 地址 - 不是 URL.
The first argument of FTP constructor is host – a hostname or an IP address – not a URL.