I am trying to make a GET request to a shopify store, packershoes as follow:
endpoint = "http://www.packershoes.com"
print session.get(endpoint, headers=headers)
When I run a get request to the site I get the following error:
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 467, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 385, in send
raise SSLError(e)
requests.exceptions.SSLError: hostname 'packershoes.com' doesn't match either of '*.myshopify.com', 'myshopify.com'
When I request a different sites, it works fine.
2
Answers
This looks like more of an SSL problem than a Python problem. You haven’t shown us your code, so I’m making some guesses here, but it looks as if the site to which you are connecting is presenting an SSL certificate that doesn’t match the hostname you’re using. The resolution here is typically:
This is discussed in the requests documentation.
Update
Taking a closer look at your problem, I notice that I cannot reproduce this problem myself. The certificates presented by
www.packershoes.com
are clearly for*.myshopify.com
, but I don’t get any certificate errors presumably because that address is actually an alias forpacker-shoes.myshopify.com
I wonder if your issue isn’t simply related to either the version of
requests
that you’re using or something in your local DNS configuration. If you replacewww.packershoes.com
in your request withpacker-shoes.myshopify.com
, does it work correctly?Requests verifies SSL certificates for HTTPS requests, just like a web browser. By default, SSL verification is enabled, and Requests will throw a
SSLError
if it’s unable to verify the certificate, you have set verify to False: