Python Pysftp 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21092850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:02:39  来源:igfitidea点击:

Python Pysftp Error

pythonsftppysftp

提问by Gavin Hinfey

My code:

我的代码:

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

I'm getting an error trying to connect to a SFTP server using pysftp.

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

This should be straight forward enough but I get the error below:

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

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

I've tried using different versions of python (mostly 2.7), I have all dependencies installed and I tried numerous sftp connections. I'm using OS X 10.9.1.

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

采纳答案by Dundee MT

That initial error appears to be a problem connecting with the remote server (SSHException). The second (AttributeError), is from a bug in the code that occurs when the connection fails. It is fixed in the latest version of pysftp

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

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

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

pip install -U pysftp

is your friend.

是你的朋友。

回答by Maviles

updating the package didn't work for me, as it was already up-to-date (latest for python 2.7 at least)

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

Found a better aproach here.

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

1) You can manualy add the ssh key to the known_hosts file

1) 您可以手动将 ssh 密钥添加到 known_hosts 文件中

ssh test.rebex.net

2) Or you can set a flag to ignore it

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