SSLError使用针对python的请求 [英] SSLError using requests for python

查看:91
本文介绍了SSLError使用针对python的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在请求快速入门中执行第一个命令:

I tried to do the first command in the Quickstart for requests:

>>> import requests
>>> r = requests.get('https://github.com/timeline.json')

但是我收到以下错误消息:

But I get the following error message:

Traceback (most recent call last):
  File "./main.py", line 16, in <module>
    requests.get('https://github.com/timeline.json')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 383, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 486, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/adapters.py", line 385, in send
    raise SSLError(e)
requests.exceptions.SSLError: [Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我对SSL证书完全陌生,但是我怀疑它与Python放置在错误的位置有关.我下载了Python 2.7,并将其用作默认的Python(我正在运行Python 2.6附带的Mac OSX 10.6(Snow Leopard)).在修复路径并建立符号链接之前,我的Mac在查找Python东西的错误位置时遇到了很多麻烦,但是我想知道是否还有其他原因与导致此SSL错误的升级有关?或可能与此无关.

I am totally new to SSL certificates, but I suspect it has something to do with Python looking in the wrong place. I downloaded Python 2.7 and am using it as my default Python (I am running Mac OSX 10.6 (Snow Leopard), which came with Python 2.6). I had a lot of trouble with my Mac looking in the wrong place for Python stuff until I fixed the paths and made symbolic links, but I wonder if there is something else that has to do with the upgrade that is causing this SSL error? Or it could be something that doesn't have anything to do with that.

我尝试搜索类似的问题,并阅读了一些人的建议,只是为了补充requests.get()中的参数verify=False,但是我不想这样做,因为我认为这可以避免真正的问题.感谢您帮助一个完整的新手.

I have tried searching for similar questions and read some people's suggestions just to add the argument verify=False in requests.get(), but I don't want to do that, since I think that just avoids the real problem. Thanks for helping out a complete newbie.

推荐答案

您可以尝试一下.

验证证书的路径:

>>> requests.get('https://whatever.com', verify='/path/to/certfile')

>>> requests.get('https://whatever.com', cert=('/path/server.crt', '/path/key'))

http://docs.python-requests.org/en/latest/user/advanced/

这篇关于SSLError使用针对python的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆