FTPLIB error socket.gaierror: [Errno 8] nodename nor servname provided, or not known(FTPLIB 错误 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)文件/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py",第 707 行,在 create_connection对于 getaddrinfo(host, port, 0, SOCK_STREAM) 中的 res:文件/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py",第 748 行,在 getaddrinfo对于 _socket.getaddrinfo 中的 res(主机、端口、家庭、类型、原型、标志):socket.gaierror: [Errno 8] nodename or servname provided, or not known
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] nodename nor servname provided, or not known的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FTPLIB 错误 socket.gaierror: [Errno 8] nodename nor servnam
基础教程推荐
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01