運行python腳本時,報錯InsecurePlatformWarning: A true SSLContext object is not available,解決方法


今天,要在新環境里運行一個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版本,但此時腳本不涉及安全的情況下,能夠正常往下執行。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM