Python 解决 InsecurePlatformWarning: A true SSLContext object is not available

问题

  • 在使用Python的requests去请求一些 https 资源的时候,会遇到以下报错信息,虽然不影响使用,但老是在屏幕上输出也不是很爽。

    /usr/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:132: 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 newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
      InsecurePlatformWarning
    

解决方法(CentOS)

  1. 需要先安装 python-devel libffi-devel openssl-devel

    yum install python-devel libffi-devel openssl-devel -y
    
  2. 再安装urllib3需要的的 pyopenssl 库就可以了

    pip install pyopenssl ndg-httpsclient pyasn1 -y