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_info0 == 2改成if sys.version_info0 == 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

相关推荐
M--Y8 小时前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
岁月宁静8 小时前
DeepSeek Harness 实战与架构解析:让 Agent 从“会聊”到“能交付”
人工智能·python·agent
LiaoWL1239 小时前
NumPy 入门实战(二):向量化与余弦相似度——从 ndarray 到 Embedding
python·numpy·embedding
forest_099 小时前
多 Agent 协作第二课:交叉验证≠独立验证
人工智能·python·算法·机器学习·prompt·agi
databook12 小时前
时间序列数据,先拆规律还是先查异常
python·数据挖掘·数据分析
师夷长技以自愈13 小时前
手搓 AI Agent 第 8 篇:从手写循环到画流程图——LangGraph 封装
人工智能·python
aifannihao14 小时前
Rust 1.100 的 DropGuard:用 Python 实测失败回滚与吞异常
python·rust·异常处理·标准库·contextlib
用户0190275816115 小时前
天勤 tqsdk 能做 A 股行情吗?期货强项与股票数据选型
python
2601_9679791217 小时前
pip在Python中的9个必须知道的用法
python·pip·版本控制·包管理工具·requirements.txt
曲径海盗17 小时前
【Python 学习第 58 天】列表方法
python·学习笔记·编程入门