Ubuntu Python 请求提取不正确的 SSL 证书

Ubuntu Python requests pulling incorrect SSL cert

Python 中的请求包似乎在 Ubuntu 中引用了不正确的 SSL 证书。我正在使用请求 2.6.2。代码在 Mac 上运行良好,但在 Ubuntu 上运行失败。感谢您的帮助!

这个请求:

query_string = https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0

requests.get(query_string, auth=(self.accessid,self.key))

产生此错误输出:

Traceback (most recent call last): File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in requests.get('https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0') File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 69, in get return request('get', url, params=params, **kwargs) File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request resp = self.send(prep, **send_kwargs) File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs) File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send raise SSLError(e, request=request) SSLError: hostname 'lsapi.seomoz.com' doesn't match either of 'incapsula.com', ...

这个问题归结为与this one: the version of Python you're using does not support SNI. Follow the advice in this answer相同。