Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

In python, on a Ubuntu server, I am trying to get the requests library to make https requests, like so:

import requests
requests.post("https://example.com")

At first, I got the following:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

After following the advice in this question: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately, I have now upgraded my warning to the following error:

AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

How do I fix this?

like image 254
Zags Avatar asked Jul 23 '15 00:07

Zags


3 Answers

The fix for me was the following:

sudo apt-get purge python-openssl
sudo pip install pyopenssl
like image 170
Zags Avatar answered Oct 20 '22 01:10

Zags


This was able to get the python working on Ubuntu 12.04.3 LTS for me.

sudo apt-get install python-dev python-pip build-essential libffi-dev
sudo -H pip install --upgrade pip setuptools && sudo -H pip install --upgrade pyopenssl
like image 45
Andrew Avatar answered Oct 19 '22 23:10

Andrew


On RedHat:

sudo yum remove pyOpenSSL
sudo pip install pyopenssl
like image 45
Ben McCann Avatar answered Oct 20 '22 01:10

Ben McCann