FTPLIB错误socket.gaierror:提供了[Errno 8]节点名或服务名,或者未知 [英] FTPLIB error socket.gaierror: [Errno 8] nodename nor servname provided, or not known
问题描述
我正在尝试使用FTPlib从FTP服务器下载文件,但我一直收到以下错误消息.我尝试了在SO上找到的几种方法,即编辑etc/host文件,并在本地主机IP后添加计算机名称,但这也不起作用.
I'm trying to download a file from an FTP server using FTPlib but i keep getting the error below. I tried several methods found on SO namely editing the etc/host file and adding the computer name after the local host IP but that doesnt work either.
我们非常感谢您的帮助.(运行mac,python 3.7,macOS Mojave 10.14.2)
Any help is much appreciated. (running a mac, python 3.7, macOS Mojave 10.14.2)
正在尝试运行的代码:
from ftplib import FTP
ftp = FTP('myftpurl')
错误:
Traceback (most recent call last):
文件",第1行,在 init 中的文件"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ftplib.py",第117行self.connect(主机)连接中的文件"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ftplib.py",第152行source_address = self.source_address)create_connection中的文件"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py",第707行对于getaddrinfo中的res(主机,端口,0,SOCK_STREAM):getaddrinfo中的文件"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py",行748用于_socket.getaddrinfo中的res(主机,端口,家庭,类型,原型,标志): socket.gaierror:[Errno 8]节点名或服务名未提供,或者未知
File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ftplib.py", line 117, in init self.connect(host) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ftplib.py", line 152, in connect source_address=self.source_address) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 707, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 8] nodename nor servname provided, or not known
推荐答案
ftp = FTP('myftpurl')
不清楚您的特定代码中实际上包含了什么 myftpurl
.
但是给定它的名称,我认为您已经尝试过 ftp://example.com
之类的东西.仅作为明确记录 FTP(..)
不需要URL,而是主机名或IP,即 FTP('example.com')
而不是 FTP('ftp://example.com')
.
It is not clear what myftpurl
actually contains in your specific code.
But given its name I assume that you've tried something like ftp://example.com
. Only, as clearly documented FTP(...)
does not expect a URL but instead a hostname or IP, i.e. FTP('example.com')
and not FTP('ftp://example.com')
.
给出一个可能与您一样的URL会导致将该URL视为主机名,即对主机名 ftp://example.com
进行查找.由于不存在这样的主机,因此会出现错误.
Given a URL like you probably do will result in treating that URL as hostname, i.e. doing a lookup for the hostname ftp://example.com
. Since such a host does not exist you get an error.
这篇关于FTPLIB错误socket.gaierror:提供了[Errno 8]节点名或服务名,或者未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!