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

相关推荐
花酒锄作田10 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪14 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽14 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战14 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋20 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者2 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者2 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh2 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅2 天前
Python函数入门详解(定义+调用+参数)
python
曲幽2 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama