python2 paramiko 各种报错解决方案

一、介绍

paramiko是一个基于SSHv2协议的python库,支持以加密和认证的方式进行远程服务器的连接,用于实现远程文件的上传、下载或通过ssh远程执行命令。

paramiko支持Python(2.7,3.4+)版本

paramiko库可直接使用pip install paramiko 安装,依赖的其他库six、pycparser、cffi、pynacl、bcrypt、enum34、ipaddress、cryptography也会被自动安装

二、各类报错及解决办法(python版本为2.7.18)

1、 No handlers could be found for logger "paramiko.transport"

这个报错的意思是paramiko.transport的日志没地方输出

解决办法:直接在代码里添加一行 paramiko.util.log_to_file("log.log") 即可,表示报错输出到日志文件log.log里

2、 /usr/local/lib/python2.7/site-packages/paramiko/transport.py:33 : CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release. from cryptography.hazmat.backends import default_backend

这个报错是因为python2版本过旧,cryptography不再对其支持

解决办法:

1)换成python3

2)修改cryptography下的**init.py源码**绕过这个提醒,把if sys.version_info[0] == 2改成if sys.version_info[0] == 1(只要是非2即可),或者把下图34行-41行全部注释掉

注:cryptography库源码位置可使用pip show cryptography命令查看

3、 raise AttributeError(name) from None
AttributeError: Raw

这个报错是Cryptography和paramiko版本不兼容导致,需要更高版本的Cryptography

最后不报错的版本为:cryptography==3.3.2 paramiko==2.12.0

相关推荐
cheniie18 小时前
python xmlrpc踩坑记录
python·踩坑·xmlrpc
咖啡の猫19 小时前
搭建Python开发环境
开发语言·python
听风吟丶21 小时前
Java 8 Stream API 高级实战:从数据处理到性能优化的深度解析
开发语言·python
文人sec1 天前
pytest1-接口自动化测试场景
软件测试·python·单元测试·pytest
secondyoung1 天前
Mermaid流程图高效转换为图片方案
c语言·人工智能·windows·vscode·python·docker·流程图
nini_boom1 天前
**论文初稿撰写工具2025推荐,高效写作与智能辅助全解析*
大数据·python·信息可视化
1***s6321 天前
Python爬虫反爬策略,User-Agent与代理IP
开发语言·爬虫·python
咖啡の猫1 天前
Python的自述
开发语言·python
重启编程之路1 天前
python 基础学习socket -TCP编程
网络·python·学习·tcp/ip