gpt4 book ai didi

Python Pysftp 错误

转载 作者:太空狗 更新时间:2023-10-29 21:17:29 24 4
gpt4 key购买 nike

我的代码:

import pysftp 
s = pysftp.Connection(host='test.rebex.net', username='demo', password='password')
data = s.listdir()
s.close()
for i in data:
print i

我在尝试使用 pysftp 连接到 SFTP 服务器时遇到错误。

这应该足够直接,但我收到以下错误:

Traceback (most recent call last):
File "/Users/gavinhinfey/Documents/Python Files/sftp_test.py", line 3, in <module>
s = pysftp.Connection(host='test.rebex.net', username='demo', password='password')
File "build/bdist.macosx-10.6-intel/egg/pysftp.py", line 55, in __init__
File "build/bdist.macosx-10.5-intel/egg/paramiko/transport.py", line 303, in __init__
paramiko.SSHException: Unable to connect to test.rebex.net: [Errno 60] Operation timed out
Exception AttributeError: "'Connection' object has no attribute '_tranport_live'" in <bound method Connection.__del__ of <pysftp.Connection object at 0x101a5a810>> ignored

我尝试过使用不同版本的 python(主要是 2.7),我安装了所有依赖项并尝试了很多 sftp 连接。我使用的是 OS X 10.9.1。

最佳答案

更新包对我不起作用,因为它已经是最新的(至少 python 2.7 是最新的)

找到更好的方法here .

1) 您可以手动将 ssh key 添加到 known_hosts 文件

ssh test.rebex.net

2) 或者你可以设置一个标志来忽略它

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None # disable host key checking.
with pysftp.Connection('host', username='me',private_key=private_key,
private_key_pass=private_key_password,
cnopts=cnopts) as sftp
# do stuff here

关于Python Pysftp 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21092850/

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