AttributeError:'_socketobject'对象没有属性'set_tlsext_host_name'

Zag*_*ags 13 python ubuntu ssl https python-requests

在python中,在Ubuntu服务器上,我试图让requests库发出https请求,如下所示:

import requests
requests.post("https://example.com")
Run Code Online (Sandbox Code Playgroud)

起初,我得到以下内容:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90:InsecurePlatformWarning:真正的SSLContext对象不可用.这可以防止urllib3正确配置SSL,并可能导致某些SSL连接失败.有关更多信息,请参阅 https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

遵循此问题中的建议:InsecurePlatformWarning:真正的SSLContext对象不可用.这可以防止urllib3正确配置SSL,我现在已将警告升级为以下错误:

AttributeError:'_socketobject'对象没有属性'set_tlsext_host_name'

我该如何解决?

Zag*_*ags 13

我的修复方法如下:

sudo apt-get purge python-openssl
sudo pip install pyopenssl
Run Code Online (Sandbox Code Playgroud)

  • 在安装pyopenssl之前,我需要`sudo apt-get install libffi-dev` (2认同)