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,告警消失。

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

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

相关推荐
小何好运暴富开心幸福3 分钟前
C++之日期类的实现
开发语言·c++·git·bash
威风的虫18 分钟前
JavaScript中的axios
开发语言·javascript·ecmascript
老赵的博客23 分钟前
c++ 是静态编译语言
开发语言·c++
Terio_my23 分钟前
Python制作12306查票工具:从零构建铁路购票信息查询系统
开发语言·python·microsoft
消失的旧时光-19431 小时前
Kotlin when 用法完整分享
android·开发语言·kotlin
万粉变现经纪人1 小时前
如何解决 pip install -r requirements.txt 约束文件 constraints.txt 仅允许固定版本(未锁定报错)问题
开发语言·python·r语言·django·beautifulsoup·pandas·pip
站大爷IP1 小时前
Python定时任务实战:APScheduler从入门到精通
python
Fairy_sevenseven1 小时前
[1]python爬虫入门,爬取豆瓣电影top250实践
开发语言·爬虫·python
ThisIsMirror1 小时前
CompletableFuture并行任务超时处理模板
java·windows·python
java1234_小锋2 小时前
TensorFlow2 Python深度学习 - TensorFlow2框架入门 - 计算图和 tf.function 简介
python·深度学习·tensorflow·tensorflow2