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

相关推荐
数据智能老司机15 分钟前
精通 Python 设计模式——分布式系统模式
python·设计模式·架构
数据智能老司机1 小时前
精通 Python 设计模式——并发与异步模式
python·设计模式·编程语言
数据智能老司机1 小时前
精通 Python 设计模式——测试模式
python·设计模式·架构
数据智能老司机1 小时前
精通 Python 设计模式——性能模式
python·设计模式·架构
c8i1 小时前
drf初步梳理
python·django
每日AI新事件1 小时前
python的异步函数
python
这里有鱼汤3 小时前
miniQMT下载历史行情数据太慢怎么办?一招提速10倍!
前端·python
databook12 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室12 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三14 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试