运用paramiko远程执行命令报错:TypeError: from_buffer() cannot return the address of the raw string withi....

博客内容涉及使用Paramiko库进行远程命令执行时遇到的类型错误,原因是paramiko、cryptography和cffi模块之间的版本不兼容。解决方法包括升级这三个模块,特别是确保cffi的版本更新,并在必要时清理并重新安装cffi以避免多个版本冲突。执行上述步骤后,问题通常能得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

运用paramiko远程执行命令报错:

from cryptography.hazmat.backends import default_backend
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
  File "test.py", line 17, in <module>
    ssh()
  File "test.py", line 8, in ssh
    ssh.connect('172.17.0.3',22,'root','111')
  File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 406, in connect
    t.start_client(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 660, in start_client
    raise e
TypeError: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object

原因分析:

paramiko和cryptography以及cffi组件模块版本不匹配。

解决方法:

先保证同时更新这三个组件模块:

pip install cffi -i https://pypi.douban.com/simple --trust -host=pypi.douban.com
pip install --upgrade cryptography -i https://pypi.douban.com/simple --trust -host=pypi.douban.com
pip install --upgrade paramiko -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

如果还是报错,可能cffi在python路径中安装了cffi的多个副本。而默认用的是老的版本的cffi副本,可以执行如下操作解决:

pip uninstall cffi

apt-get purge --auto-remove python-cffi

pip install cffi -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

至此,应该是可以成功了。 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值