我该如何修复 SSL 错误,似乎没有任何作用?
我正打算使用 Nasa API 进行一些测试,看看它是否有效,但每次运行代码时都会出现 SSL 错误。我尝试提供 SSL 上下文并设置 verify=False,但似乎没有任何效果。
这是请求:
with urllib.request.urlopen(url=apod["hdurl"], context=ctx) as u, \
open(filename, 'wb') as f:
f.write(u.read())
在请求之上,我定义了上下文:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
因为我在 MacOS 上,所以我也尝试过“应用程序”>“ Python 3.8 >安装证书命令,但它似乎不起作用。 我认为我的 Python 解释器可能有问题。
另外,这是我得到的异常:
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1124)
似乎库本身在发送请求时遇到问题,如果我去:
nasa = nasapy.Nasa(key=key)
nasa.picture_of_the_day()
我得到相同的 SSL 证书错误。我该如何解决这个问题?
非常感谢帮助!
I was just about to do some testing with the Nasa API to see if it works, but I'm getting SSL errors every time I run the code. I tried providing SSL context, and setting verify=False, but nothing seems to work.
Here's the request:
with urllib.request.urlopen(url=apod["hdurl"], context=ctx) as u, \
open(filename, 'wb') as f:
f.write(u.read())
Above the request, I have defined the context:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
Since I'm on MacOS I've also tried going Applications > Python 3.8 > Install certificates command, but it doesn't seem to work.
I'm thinking something might be wrong with my Python interpreter.
Also, here's the exception I get:
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1124)
Seems like the library it's self is having trouble sending requests, if i go:
nasa = nasapy.Nasa(key=key)
nasa.picture_of_the_day()
I get the same SSL certificate error. How might I go about solving this?
Help much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修复了它,我必须进入库文件 venv/bin/api.py 并在请求所在的库代码中设置
verify=False
。现在可以工作了。
I fixed it, i had to go into the library files venv/bin/api.py and inside the libraries code where the request is, set
verify=False
.Works now.