【问题标题】:paramiko.ssh_exception.SSHException: Expecting packet from (31,), got 94paramiko.ssh_exception.SSHException: 期待来自 (31,) 的数据包,得到 94
【发布时间】:2015-05-27 05:48:57
【问题描述】:

当我使用 pysftp-0.2.8 将大文件发送到我的 sftp 服务时。总是报同样的错误:paramiko.ssh_exception.SSHException: Expecting packet from (31,), got 94

文件大约1.5G,500M传输就坏了。 代码在这里:

import pysftp
upftp=FTP(host=ftp_ip, user=ftp_name, passwd=ftp_passwd, acct=ftp_port, timeout=None)
...

try:
    upftp.storbinary('STOR %s'%obj[2], fp, 8192, self.callpecent)      
except Exception as error:
    fp.close()
    self.endit(upftp, 1, '%s,%s'%(obj[2],error), '%s,%s'%(obj[2],error)

)

这里的错误信息:

2015-03-24 09:43:05  DEBUG - Rekeying (hit 32729 packets, 536900100 bytes sent)

2015-03-24 09:43:05  DEBUG - Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
2015-03-24 09:43:05  DEBUG - using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
2015-03-24 09:43:05  ERROR - Exception: Expecting packet from (31,), got 94
2015-03-24 09:43:05  ERROR - Traceback (most recent call last):
2015-03-24 09:43:05  ERROR -   File "D:\Python34\lib\site-packages\paramiko-1.14.0-py3.4.egg\paramiko\transport.py", line 1435, in run
2015-03-24 09:43:05  ERROR -     raise SSHException('Expecting packet from %r, got %d' % (self._expected_packet, ptype))
2015-03-24 09:43:05  ERROR - paramiko.ssh_exception.SSHException: Expecting packet from (31,), got 94
2015-03-24 09:43:05  ERROR - 
2015-03-24 09:43:05  DEBUG - Dropping user packet because connection is dead.
2015-03-24 09:43:05  DEBUG - [chan 1] close(b'd40b000000000000')
2015-03-24 09:43:05  INFO - [chan 1] sftp session closed.

感谢您的回答!

【问题讨论】:

  • 刚刚碰到这个。找到什么让它工作了吗?
  • @Matti - 如果你还没有弄清楚 - 我在下面发布了一个答案可能会有所帮助。

标签: python paramiko pysftp


【解决方案1】:

我遇到了类似的问题 - 事实证明这是 Paramiko 的一个已知问题。我在他们的 GitHub https://github.com/paramiko/paramiko/issues/175#issuecomment-24125451 上找到了解决方案。 This one 也有点类似。

另一个答案指出了正在发生的事情,但没有给出太多的工作。对我来说,修复归结为...

self.ssh_client.connect(...)

# -- the important lines
transport = self.ssh_client.get_transport()
transport.default_window_size = 2147483647
transport.packetizer.REKEY_BYTES = pow(2, 40)
transport.packetizer.REKEY_PACKETS = pow(2, 40)
# ---

self.sftp_client = self.ssh_client.open_sftp()
print(self.sft_client.get_channel().in_window_size)
print(sftp_connection.get_channel().in_max_packet_size)

# Output

2147483647
32768

【讨论】:

  • 太棒了,我会保存这个 sn-p 以备将来使用。在我的情况下,我最终切换到系统的 sftp,我现在通过 Pexpect 包调用它。这样我也看到了更好的吞吐量。
【解决方案2】:

我发现有些东西可能有用:)

in the paramiko/packet.py

REKEY_PACKETS = pow(2, 29)
REKEY_BYTES = pow(2, 29)

REKEY_PACKETS_OVERFLOW_MAX = pow(2, 29)     # Allow receiving this many packets after a re-key request before terminating
REKEY_BYTES_OVERFLOW_MAX = pow(2, 29)       # Allow receiving this many bytes after a re-key request before terminating

    def _trigger_rekey(self):
    # outside code should check for this flag
    self.__need_rekey = True

当它使用re-key时,它会出错。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 2021-09-17
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多