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盘容量不够,python , pip,安装包的位置
linux·python·pip
时见先生3 小时前
Python库和conda搭建虚拟环境
开发语言·人工智能·python·自然语言处理·conda
二十雨辰3 小时前
[python]-循环语句
服务器·python
a努力。3 小时前
国家电网Java面试被问:混沌工程在分布式系统中的应用
java·开发语言·数据库·git·mysql·面试·职场和发展
Yvonne爱编码3 小时前
Java 四大内部类全解析:从设计本质到实战应用
java·开发语言·python
wqwqweee3 小时前
Flutter for OpenHarmony 看书管理记录App实战:搜索功能实现
开发语言·javascript·python·flutter·harmonyos
yongui478344 小时前
基于MATLAB的NALM锁模光纤激光器仿真实现
开发语言·matlab
-To be number.wan5 小时前
Python数据分析:numpy数值计算基础
开发语言·python·数据分析
Cx330❀6 小时前
【优选算法必刷100题】第038题(位运算):消失的两个数字
开发语言·c++·算法·leetcode·面试
Loo国昌6 小时前
深入理解 FastAPI:Python高性能API框架的完整指南
开发语言·人工智能·后端·python·langchain·fastapi