gpt4 book ai didi

python-2.7 - socket.gaierror : [Errno 8] nodename nor servname provided, 或未知

转载 作者:行者123 更新时间:2023-12-03 12:32:06 25 4
gpt4 key购买 nike

我正在尝试在运行 OS X Yosemite (10.10.5) 的 Mac 上使用以下 Python 脚本连接到我的 ftp 服务器:

from ftplib import FTP
import ConfigParser

config_file = "ftp.config"
config = ConfigParser.ConfigParser()
try:
config.read(config_file)
except:
raise Exception("Failed reading {} file.").format(config_file)

server_address = config.get("main", "server")
user_name = config.get("main", "user_name")
password = config.get("main", "password")

ftp = FTP(server_address)
ftp.login(user_name, password)
print "Logging in as '{}'".format(user_name)

该脚本从文件“ftp.config”中获取服务器信息,内容如下:
[main]
enable = 1
server = "my.ftp.address"
user_name = "some_user_name"
password = "some_password"

当我运行脚本时,出现以下错误:
Traceback (most recent call last):  
File "ftp2.py", line 34, in <module>
ftp = FTP(server_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py", line 120, in __init__
self.connect(host)
File "/System/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 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

我不知道为什么会发生错误。我试图对“.config”文件中的字符串进行 .split(),以删除多余的行,但这似乎没有帮助。

有什么想法吗,伙计们?

谢谢。

最佳答案

删除配置文件中的引号

[main]
enable = 1
server = my.ftp.address
user_name = some_user_name
password = some_password

关于python-2.7 - socket.gaierror : [Errno 8] nodename nor servname provided, 或未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32046587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com