gpt4 book ai didi

python - 使用 Paramiko 连接到 SFTP 服务器时为 "getaddrinfo failed"

转载 作者:行者123 更新时间:2023-12-01 07:00:00 32 4
gpt4 key购买 nike

我尝试连接到 SFTP 服务器,但返回错误:

[Errno 11001] getaddrinfo failed

我使用的是Python 3.7.3,Paramiko版本是2.6.0

import paramiko

host_name = "sftp://81.149.151.143"
user_name = "******"
password = "******"

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=host_name, port=220, username=user_name, password=password)

ftp_client=ssh_client.open_sftp()
ftp_client.put('***/issue_1.docx', '/issue_1.docx')
ftp_client.close()

这是完整的错误:

Traceback (most recent call last):
File "/sftp/paramiko_bot.py", line 10, in <module>
ssh_client.connect(hostname=host_name, port=22, username=user_name, password=password)
File "\Local\Programs\Python\Python37\lib\site-packages\paramiko\client.py", line 340, in connect
to_try = list(self._families_and_addresses(hostname, port))
File "\Local\Programs\Python\Python37\lib\site-packages\paramiko\client.py", line 204, in _families_and_addresses
hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM
File "\AppData\Local\Programs\Python\Python37\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

最佳答案

SSHClient.connect主机名参数应包含 hostname仅(或者在您的情况下是 IP 地址) – 不是任何类型的 URL。

ssh_client.connect(hostname="81.149.151.143", port=220, username=..., password=...)
<小时/>

强制警告:请勿以这种方式使用 AutoAddPolicy – 您将失去针对 MITM attacks 的保护通过这样做。正确的解决方案请参见 Paramiko "Unknown Server" .

关于python - 使用 Paramiko 连接到 SFTP 服务器时为 "getaddrinfo failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58683322/

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