运行python脚本时,报错InsecurePlatformWarning: A true SSLContext object is not available,解决方法...

本文记录了解决Python环境中出现的InsecurePlatformWarning警告的过程。通过安装和更新requests库,成功解决了该警告,并附带出现了CryptographyDeprecationWarning警告,但不影响脚本执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天,要在新环境里运行一个python脚本,遇到下面的报错:

/usr/lib/python2.7/site-packages/urllib3/util/ssl_.py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a new......

报错跟安全策略相关,网上搜了下,是因为python版本的原因(用的是python2.7.5),解决办法要么升级python 版本,要么安装requests,

本着牵动最小的原则,决定采用后者,如下:

pip install requests[security]   

安装完成后,重新运行python脚本,还是一样的报错,又尝试了

pip install pyopenssl ndg-httpsclient pyasn1(等同于安装requests)

安装完成后,重新运行python脚本,还是一样的报错,想到一个惯用伎俩——upgrade

pip install --upgrade requests[security]

安装完成后,重新运行python脚本,果然,不再报InsecurePlatformWarning错了

 

题外话:InsecurePlatformWarning的错没有了,但又报了另一个错CryptographyDeprecationWarning,详细信息如下:

/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.

  utils.DeprecatedIn23

 

提醒升级python版本,但此时脚本不涉及安全的情况下,能够正常往下执行。

 

 

转载于:https://www.cnblogs.com/jjstrip/p/9494150.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值