python运行报错CryptographyDeprecationWarning,Upgrade pyOpenSSL now.

【问题描述】

运行一段含有AES加解密的代码,总是有warning提示出现,如下:

D:\Python38\lib\site-packages\cryptography\hazmat\backends\openssl\x509.py:14: CryptographyDeprecationWarning: This version of cryptography contains a temporary pyOpenSSL fallback path. Upgrade pyOpenSSL now.

warnings.warn(

虽然不影响代码运行,但看着还是有点不爽,于是向办法消除告警。

【问题分析】

涉及出问题代码为x509.py,涉及问题根据告警提示为:pyOpenSSL版本过低。

x509.py中涉及源码如下:

This exists for pyOpenSSL compatibility and SHOULD NOT BE USED

WE WILL REMOVE THIS VERY SOON.

def _Certificate(backend, x509) -> x509.Certificate: # noqa: N802
warnings.warn(
"This version of cryptography contains a temporary pyOpenSSL "
"fallback path. Upgrade pyOpenSSL now.",
utils.DeprecatedIn35,
)
return backend._ossl2cert(x509)

经查pip list,发现版本如下:

pycryptodome 3.15.0

pyOpenSSL 22.0.0

【解决方案】

1.临时解决方案----关闭此告警

在运行主代码的头部,加入如下代码:

import warnings

warnings.filterwarnings(action='ignore',module='.*cryptography.*')

其中过滤掉cryptography是因为在x509.py中有语句:

from cryptography import utils, x509

说明是 导入cryptography时出现问题的。

2.终极解决方案---升级对应库版本。

pip uninstall pyOpenSSL

pip install pyOpenSSL

Attempting uninstall: cryptography

Found existing installation: cryptography 36.0.2

Uninstalling cryptography-36.0.2:

Successfully uninstalled cryptography-36.0.2

Successfully installed cryptography-42.0.5 pyOpenSSL-24.0.0

最终升级至24.0.0,告警消失。

以上分析过程,应该对大家处理日常故障有一定参考价值。

【发文章不易,请大家多多点赞、关注、收藏、支持!谢谢!!】

相关推荐
lntu_ling1 天前
Python-基于Haversine公式计算两点距离
开发语言·python·gis算法
ShineWinsu1 天前
对于C++:继承的解析—上
开发语言·数据结构·c++·算法·面试·笔试·继承
小付同学呀1 天前
C语言学习(五)——输入/输出
c语言·开发语言·学习
梦幻精灵_cq1 天前
学C之路:不可或缺的main()主函数框架(Learn-C 1st)
c语言·开发语言
哈里谢顿1 天前
Django 应用 OOM(Out of Memory)故障的定位思路和排查方法
python·django
消失的旧时光-19431 天前
C++ 多线程与并发系统取向(二)—— 资源保护:std::mutex 与 RAII(类比 Java synchronized)
java·开发语言·c++·并发
甄心爱学习1 天前
【python】获取所有长度为 k 的二进制字符串
python·算法
福大大架构师每日一题1 天前
go-zero v1.10.0发布!全面支持Go 1.23、MCP SDK迁移、性能与稳定性双提升
开发语言·后端·golang
tuotali20261 天前
氢气压缩机技术规范亲测案例分享
人工智能·python
嫂子的姐夫1 天前
030-扣代码:湖北图书馆登录
爬虫·python·逆向