运行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版本,但此时脚本不涉及安全的情况下,能够正常往下执行。

 

 

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

发布了152 篇原创文章 · 获赞 62 · 访问量 23万+
展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

python使用pip安装beautifulsoup4总是抛异常安装不了

07-12

python使用pip安装beautifulsoup4总是抛异常安装不了--- 求解答 ------------------------------------------------------------ D:\Python27\Scripts>pip install beautifulsoup4 Collecting beautifulsoup4 D:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissi TPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not avail tform. This may cause the server to present an incorrect TLS certificate, which can cause vali You can upgrade to a newer version of Python to solve this. For more information, see https:/ docs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning D:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: Insecure A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropr ause certain SSL connections to fail. You can upgrade to a newer version of Python to solve th ormation, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading beautifulsoup4-4.4.1-py2-none-any.whl (81kB) Exception: Traceback (most recent call last): File "D:\Python27\lib\site-packages\pip\basecommand.py", line 215, in main status = self.run(options, args) File "D:\Python27\lib\site-packages\pip\commands\install.py", line 299, in run requirement_set.prepare_files(finder) File "D:\Python27\lib\site-packages\pip\req\req_set.py", line 370, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "D:\Python27\lib\site-packages\pip\req\req_set.py", line 587, in _prepare_file session=self.session, hashes=hashes) File "D:\Python27\lib\site-packages\pip\download.py", line 810, in unpack_url hashes=hashes File "D:\Python27\lib\site-packages\pip\download.py", line 649, in unpack_http_url hashes) File "D:\Python27\lib\site-packages\pip\download.py", line 871, in _download_http_url _download_url(resp, link, content_file, hashes) File "D:\Python27\lib\site-packages\pip\download.py", line 595, in _download_url hashes.check_against_chunks(downloaded_chunks) File "D:\Python27\lib\site-packages\pip\utils\hashes.py", line 46, in check_against_chunks for chunk in chunks: File "D:\Python27\lib\site-packages\pip\download.py", line 563, in written_chunks for chunk in chunks: File "D:\Python27\lib\site-packages\pip\utils\ui.py", line 139, in iter for x in it: File "D:\Python27\lib\site-packages\pip\download.py", line 552, in resp_read decode_content=False): File "D:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line data = self.read(amt=amt, decode_content=decode_content) File "D:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line flush_decoder = True File "D:\Python27\lib\contextlib.py", line 35, in __exit__ self.gen.throw(type, value, traceback) File "D:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line catcher raise ReadTimeoutError(self._pool, None, 'Read timed out.') ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览