requests icon indicating copy to clipboard operation
requests copied to clipboard

SSLError from imgur API, however proper cert appears via Chrome

Open maxcountryman opened this issue 13 years ago • 12 comments

>>> import requests; requests.get('https://api.imgur.com') 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 279, in request
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 374, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 213, in send
    raise SSLError(e)
requests.exceptions.SSLError: hostname 'api.imgur.com' doesn't match 'imgur.com'

maxcountryman avatar Jan 22 '13 03:01 maxcountryman

You could use verify=False

sigmavirus24 avatar Jan 22 '13 03:01 sigmavirus24

It's pretty trivial to get around, but if this isn't on imgur's end then I think it merits further investigation on requests' end. If the certs are installed correctly then it seems like this shouldn't happen and would indicate a bug.

maxcountryman avatar Jan 22 '13 03:01 maxcountryman

This may be a bug somewhere in the chain because upon further investigation, it does have a valid certificate (according to firefox). I have no clue where the problem may lie though.

sigmavirus24 avatar Jan 22 '13 03:01 sigmavirus24

Using my crazy Raymond Chen-esque mind powers, I deduce that you are running a version of Python less than 3.2, and are therefore being hit by #749.

Unfortunately, resolving #749 on these earlier versions of Python requires some serious changes to urllib3, which no-one has gotten around to making yet.

Lukasa avatar Jan 22 '13 09:01 Lukasa

@Lukasa you are absolutely correct in your deduction: I am in fact using Python 2.7.x.

That is terribly unfortunate apropos of urllib3 and a little surprising considering how widespread Python 2.x usage still is...

maxcountryman avatar Jan 22 '13 16:01 maxcountryman

You could replace the bundled urllib3 with the one from the branch from my latest pull request to urllib3 (see above your post). Then do something along the line of http://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/ but setting the verify_hostname parameter to PoolManager / adding a function which changes this only for imgur.

t-8ch avatar Jan 22 '13 16:01 t-8ch

@maxcountryman: The reason the changes have not yet been made in urllib3 is that the SNI hostname parameter is not exposed in the default library ssl module before Python 3.2. To implement this behaviour would require doing something intelligent with PyOpenSSL, a third party module. I'm beginning to think about doing this, but I certainly won't start before the weekend. =)

Lukasa avatar Jan 22 '13 18:01 Lukasa

@Lukasa you're right. It is exclusive to python 2.x (I tested on 2.6). Testing again on python 3.2 works just fine.

sigmavirus24 avatar Jan 26 '13 17:01 sigmavirus24

The cacert.pem needs to be updated.

In my PIP environment //lib/python2.7/site-packages/requests/ the cacert.pem is oooooooold need to update

nacht avatar Jan 29 '13 18:01 nacht

Actually - scratch my response - this SSL error is different to the one I'm seeing - but I'll keep my comment in case anyone googles it/looks for it.

nacht avatar Jan 29 '13 18:01 nacht

Also, the cert is being updated in #1149. We just need to remove any blacklisted certs that are in there. /ping @nacht ;)

sigmavirus24 avatar Feb 09 '13 23:02 sigmavirus24

closing, we need to update our certs again

kennethreitz avatar Feb 10 '13 22:02 kennethreitz