SSLError from imgur API, however proper cert appears via Chrome
>>> 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'
You could use verify=False
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.
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.
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 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...
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.
@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 you're right. It is exclusive to python 2.x (I tested on 2.6). Testing again on python 3.2 works just fine.
The cacert.pem needs to be updated.
In my PIP environment /
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.
Also, the cert is being updated in #1149. We just need to remove any blacklisted certs that are in there. /ping @nacht ;)
closing, we need to update our certs again