skip to Main Content

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


  1. 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:

    • See if there is an alternative hostname you should/could be using that would match the hostname in the certificate,
    • Report the problem to the site you’re trying to access and see if there is a configuration error on their end, or
    • Disable certificate validation in your code. You don’t really want to do that because it would open your code up to man-in-the-middle attacks.

    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 for packer-shoes.myshopify.com

    $ host www.packershoes.com
    www.packershoes.com is an alias for packer-shoes.myshopify.com.
    packer-shoes.myshopify.com is an alias for shops.myshopify.com.
    shops.myshopify.com has address 23.227.38.64
    

    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 replace www.packershoes.com in your request with packer-shoes.myshopify.com, does it work correctly?

    Login or Signup to reply.
  2. 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:

    session.get("http://www.packershoes.com", headers=headers, verify=False)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search