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

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

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

相关推荐
zaim11 分钟前
计算机的错误计算(二百二十六)
java·python·c#·c·错数·mpmath
EmmaXLZHONG2 分钟前
Django By Example - 学习笔记
笔记·python·学习·django
不写八个4 分钟前
PHP教程005:配置ThinkPHP环境
开发语言·php
迷海5 分钟前
C++内存对齐
开发语言·c++
ZC跨境爬虫6 分钟前
Playwright进阶操作:鼠标拖拽与各类点击实战(含自定义拖拽实例)
前端·爬虫·python·ui
炘爚9 分钟前
C++(流类:istream /ostream/istringstream /ostringstream)
开发语言·c++·算法
kvo7f2JTy9 分钟前
全面解析 Mineru:高效文件解析工具的核心参数详解
python
心静财富之门10 分钟前
《前端零基础入门:HTML + CSS + JavaScript 全套速查表(详细版 + 实例)》
前端·javascript·python
Gse0a362g15 分钟前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
android·开发语言·php