報錯信息
上午的時候數據組的同事跟我說有幾個程序報錯,經過查看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)
經過測試,兩次打印出來的屬性值不同,說明屬性設置成功,問題解決。