[錯誤解決]paramiko.ssh_exception.SSHException: Error reading SSH protocol banner 設置


報錯信息

上午的時候數據組的同事跟我說有幾個程序報錯,經過查看log發現找到報錯信息:

paramiko.ssh_exception.SSHException: Error reading SSH protocol banner

經過搜索,得知引起該錯誤的原因是因為banner_timeout默認設置太短,只有15s。

錯誤分析

經查看paramiko庫下面的transport.py下面的Transport代碼如下:

class Transport(threading.Thread, ClosingContextManager):
        self.banner_timeout = 15
        # how long (seconds) to wait for the handshake to finish after SSH

重設banner_timeout屬性值

網上的方法大多數是修改源碼,重新安裝,感覺略麻煩。這里在代碼里面進行屬性重新設置。

transport = paramiko.Transport((self.host, self.port))
print(transport.banner_timeout)
transport.banner_timeout = 30
print(transport.banner_timeout)

經過測試,兩次打印出來的屬性值不同,說明屬性設置成功,問題解決。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM