Accessing FTP server with Python fails with “getaddrinfo” error

坚强是说给别人听的谎言 提交于 2020-07-15 08:18:45

问题


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.

Code:

from ftplib import FTP
ftp = FTP('ftp://ftp.dlptest.com/')
...

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\ftplib.py", line 120, in __init__
    self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 135, 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):
socket.gaierror: [Errno 11001] getaddrinfo failed

Any help is appreciated!


回答1:


Use

ftp = FTP('ftp.dlptest.com')

instead.

The first argument of FTP constructor is host – a hostname or an IP address – not a URL.



来源:https://stackoverflow.com/questions/62780350/accessing-ftp-server-with-python-fails-with-getaddrinfo-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!