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

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

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

相关推荐
gCode Teacher 格码致知2 小时前
Pandas教学-18:number与numeric的区别
python·pandas
梦想不只是梦与想5 小时前
Python 中subprocess 模块:执行外部命令
python·subprocess·调用外部命令
懂点Tech5 小时前
ctfshow MISC入门图片篇(信息附加):misc41解题思路
开发语言·python
catchadmin6 小时前
PHP 8.7 协程新提案 让跨协程代码共享请求身份
开发语言·php
念何架构之路7 小时前
go-grpc设计思想
开发语言·后端·golang
酷炫码神7 小时前
Day 10|Pinia 状态管理:把散落在各组件的数据,收进一个全局仓库
android·开发语言·javascript
Elastic 中国社区官方博客8 小时前
我们如何通过 70 多个拉取请求,将 OpenTelemetry Java agent 迁移到 invokedynamic
java·大数据·开发语言·elasticsearch·搜索引擎·全文检索·es
tyn1888 小时前
记录本地安装nacos服务的方法及异常
java·开发语言
步行cgn9 小时前
Spring MVC 视图机制的核心接口与类
java·开发语言·后端·spring·mvc
传奇开心果编程10 小时前
【Rust入门练中学】第5课:引用与借用
开发语言·rust·引用·编程语言理论·通用编程语言·借用