Python Pysftp 错误

新手上路,请多包涵

我的代码:

 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。

原文由 Gavin Hinfey 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 635
2 个回答

最初的错误似乎是与远程服务器的连接问题 (SSHException)。第二个 (AttributeError) 来自连接失败时发生的代码错误。它已在最新版本的pysftp中修复

https://pypi.python.org/pypi/pysftp

 pip install -U pysftp

是你的朋友。

原文由 Dundee MT 发布,翻译遵循 CC BY-SA 3.0 许可协议

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

在这里 找到了更好的方法。

  1. 您可以手动将 ssh 密钥添加到 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

原文由 Maviles 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题