python requests SSLError

2.8k Views Asked by At

While trying to use the SnapWrap library I've come across this error:

  File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: hostname 'android.clients.google.com' doesn't match either of '*.google.com', '*.android.com', '*.appengine.google.com', '*.cloud.google.com', '*.google-analytics.com', '*.google.ca', '*.google.cl', '*.google.co.in', '*.google.co.jp', '*.google.co.uk', '*.google.com.ar', '*.google.com.au', '*.google.com.br', '*.google.com.co', '*.google.com.mx', '*.google.com.tr', '*.google.com.vn', '*.google.de', '*.google.es', '*.google.fr', '*.google.hu', '*.google.it', '*.google.nl', '*.google.pl', '*.google.pt', '*.googleadapis.com', '*.googleapis.cn', '*.googlecommerce.com', '*.googlevideo.com', '*.gstatic.cn', '*.gstatic.com', '*.gvt1.com', '*.gvt2.com', '*.metric.gstatic.com', '*.urchin.com', '*.url.google.com', '*.youtube-nocookie.com', '*.youtube.com', '*.youtubeeducation.com', '*.ytimg.com', 'android.com', 'g.co', 'goo.gl', 'google-analytics.com', 'google.com', 'googlecommerce.com', 'urchin.com', 'youtu.be', 'youtube.com', 'youtubeeducation.com'

Using google I've come across this answer but haven't been able to find urllib3 in site-packages

How can this be fixed?

2

There are 2 best solutions below

0
On BEST ANSWER

Your version of python does not support SNI yet, which is needed to get the proper certificates on sites which have multiple certificates per IP address.

Without SNI you get a certificate for *.google.com and others (see the error message), but none of these match the hostname android.clients.google.com because the wildcard matches only a single label and android.clients are two labels. But with SNI you get the certificate for *.clients.google.com which matches the provided hostname and validates fine.

SNI support for python is available with Python 3.x and with Python 2.7.9+, so you need to upgrade.

4
On

As you are using Python 2.7 you need to install request instead urllib3.

pip install request

Please let me know if still you face the problems.