我正在尝试从 ipython 会话打开 SFTP 连接。但是我的代码
import grequests
import pysftp
sftp = pysftp.Connection(
'ftp.server.com',
port=2255,
username='myname',
private_key='/Users/myname/.ssh/rsa')
提高
Traceback (most recent call last):
File "/Users/myname/reporting-python/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3066, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-11-82bba0e75aee>", line 5, in <module>
private_key='/Users/myname/.ssh/rsa') # TODO: adjust key path
File "/Users/myname/reporting-python/lib/python2.7/site-packages/pysftp.py", line 187, in __init__
self._transport.connect(username=username, pkey=prv_key)
File "/Users/myname/reporting-python/lib/python2.7/site-packages/paramiko/transport.py", line 1072, in connect
self.start_client()
File "/Users/myname/reporting-python/lib/python2.7/site-packages/paramiko/transport.py", line 492, in start_client
raise e
SSHException: Error reading SSH protocol bannerThis operation would block forever
从 OSX 终端连接到服务器没有问题:
sftp -oPort=2255 -oUser=myname -oPubkeyAuthentication=yes -oIdentityFile=/Users/myname/.ssh/rsa ftp.server.com
我已经尝试在 transport.py 中将横幅超时从 15 秒更改为 60 秒,但并没有解决问题。
paramiko.SSHException: Error reading SSH 协议横幅建议检查横幅,但是我不知道如何使用此信息来解决问题。
更新:
似乎问题是由导入包grequests引起的。如果我不导入 grequests,pysftp 会按预期工作。这个问题之前提出过,但一直没有解决。