问题描述:
运用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
至此,应该是可以成功了。