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

相关推荐
Java后端的Ai之路19 小时前
【Python 教程15】-Python和Web
python
冬奇Lab20 小时前
一天一个开源项目(第15篇):MapToPoster - 用代码将城市地图转换为精美的海报设计
python·开源
二十雨辰1 天前
[python]-AI大模型
开发语言·人工智能·python
Yvonne爱编码1 天前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
前端摸鱼匠1 天前
YOLOv8 环境配置全攻略:Python、PyTorch 与 CUDA 的和谐共生
人工智能·pytorch·python·yolo·目标检测
WangYaolove13141 天前
基于python的在线水果销售系统(源码+文档)
python·mysql·django·毕业设计·源码
AALoveTouch1 天前
大麦网协议分析
javascript·python
ZH15455891311 天前
Flutter for OpenHarmony Python学习助手实战:自动化脚本开发的实现
python·学习·flutter
xcLeigh1 天前
Python入门:Python3 requests模块全面学习教程
开发语言·python·学习·模块·python3·requests
xcLeigh1 天前
Python入门:Python3 statistics模块全面学习教程
开发语言·python·学习·模块·python3·statistics