About paramiko, is it bug or environmental problem? how to solve it?

recently, my colleagues encountered a rare problem when using python"s paramiko library, which I ignored once, but now needs to be resolved. When using paramiko for file drop-down, an exception occurs. The code and error message are as follows:

-sharp -*- coding: utf-8 -*-

import paramiko

def test():
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname="xxxx", port=22, username="root", password="", compress=True)
    channel = ssh.get_transport()
    sftp = paramiko.SFTPClient.from_transport(channel)
    sftp = ssh.open_sftp()
    sftp.get("/tmp/device.conf", "./device.conf")

if __name__ == "__main__":
    test()

Traceback (most recent call last):
  File "C:/Users/ts/Desktop/test.py", line 15, in <module>
    test()
  File "C:/Users/ts/Desktop/test.py", line 10, in test
    sftp = paramiko.SFTPClient.from_transport(channel)
  File "E:\Python2.7_64\lib\site-packages\paramiko\sftp_client.py", line 140, in from_transport
    return cls(chan)
  File "E:\Python2.7_64\lib\site-packages\paramiko\sftp_client.py", line 103, in __init__
    server_version = self._send_version()
  File "E:\Python2.7_64\lib\site-packages\paramiko\sftp.py", line 107, in _send_version
    t, data = self._read_packet()
  File "E:\Python2.7_64\lib\site-packages\paramiko\sftp.py", line 174, in _read_packet
    x = self._read_all(4)
  File "E:\Python2.7_64\lib\site-packages\paramiko\sftp.py", line 162, in _read_all
    out += x
TypeError: cannot concatenate "str" and "tuple" objects

look at the error message, you can"t add variables of type str and tuple, but this is an error in paramiko library. After I started breakpoint debugging, I found that the initial value of out is "", x is the data received by self.sock.recv in the code, and the type of x is tuple. A structure like ("", None) ", where x [0] is the really needed value. So my temporary solution is to add an x variable type judgment, if x is a string, then out + = x, if x is tuple, then out + = x [0]. In this way, the program can run normally, and the result is the same as expected.
has anyone ever encountered the same situation? How do you solve it?
ps: colleague development environment: win7 x64 python 2.7 64-bit

Feb.07,2022
Menu