Python pysft/paramiko 'EOF during negotiation' error

陌路散爱 提交于 2019-12-24 01:43:31

问题


I'm using pysftp to download and upload some files. This exact same code I just run an hour before and was fine, but now I got this 'EOF during negotiation' error. What am I missing here?

>>> sftp = pysftp.Connection(host, username=user, password=pasw)
>>> sftp
<pysftp.Connection object at 0x7f88b25bb410>
>>> sftp.cd('data')
<contextlib.GeneratorContextManager object at 0x7f88b1a86910>
>>> sftp.exists(filename)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pysftp/__init__.py", line 827, in exists
    self._sftp_connect()
  File "/usr/local/lib/python2.7/dist-packages/pysftp/__init__.py", line 205, in _sftp_connect
    self._sftp = paramiko.SFTPClient.from_transport(self._transport)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 132, in from_transport
    return cls(chan)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 101, in __init__
    raise SSHException('EOF during negotiation')
paramiko.ssh_exception.SSHException: EOF during negotiation

EDIT: Enabled loggin for paramiko.transport and got the following:

>>> import logging; logging.basicConfig(); logging.getLogger('paramiko.transport').setLevel(logging.DEBUG)
>>> sftp = pysftp.Connection(host, username=user, password=pasw)
DEBUG:paramiko.transport:starting thread (client mode): 0x27313b0L
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.16.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_4.3p2
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_4.3p2)
DEBUG:paramiko.transport:kex algos:[...] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Attempting password auth...
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
>>> sftp.cd('data')
<contextlib.GeneratorContextManager object at 0x027371D0>
>>> sftp.exists(filename)
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
Traceback (most recent call last):
DEBUG:paramiko.transport:[chan 0] EOF received (0)
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pysftp.py", line 802, in exists
DEBUG:paramiko.transport:[chan 0] EOF sent (0)
    self._sftp_connect()
  File "C:\Python27\lib\site-packages\pysftp.py", line 192, in _sftp_connect
    self._sftp = paramiko.SFTPClient.from_transport(self._transport)
  File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 132, in from_transport
    return cls(chan)
  File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 101, in __init__
    raise SSHException('EOF during negotiation')
paramiko.ssh_exception.SSHException: EOF during negotiation
>>>

Still no clue of what is wrong...


回答1:


I got this same error in a program using password authentication. Figured out it was because the password on the SFTP server had expired. Reset it, and everything worked.




回答2:


Turns out this was a connection issue in the SFTP server. Contacted the SFTP admin who fixed it, and now the same code works fine.




回答3:


For what it's worth, in my particular case, it was because someone had commented out the SFTP Subsystem in OpenSSH. Read more about how to enable it here: https://serverfault.com/q/660160/453708




回答4:


this is how i fixed : "/etc/ssh/sshd_config" i am using the centos and then i saw the this line(#) which was the wrong binary for the sftp for me, then i found the the good one and it's seem's to be working for me:

Subsystem sftp /usr/libexec/openssh/sftp-server
#Subsystem sftp /usr/lib/openssh/sftp-server

for lsb or debian try this :

Subsystem sftp internal-sftp

thank you.



来源:https://stackoverflow.com/questions/38554629/python-pysft-paramiko-eof-during-negotiation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!