gpt4 book ai didi

python - SSL:尝试打开 Nav Canada 网站时出现 CERTIFICATE_VERIFY_FAILED

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:05 26 4
gpt4 key购买 nike

我创建了一个脚本,它从位于以下地址的 Nav Canada 网站上抓取最新的航空天气数据;

https://flightplanning.navcanada.ca/cgi-bin/lab/lab.cgi?Langue=anglais&NoSession=NS_Inconnu&TypeBrief=L&Version=T&AerodromeId=CYOW&cw_metar=dcd_metar&fw_gfaCld=on&fw_gfaIcg=on&rwt_uprWindsFD180=on

我使用这些数据来计算一些变量,并使用 raspberry pi 将其显示在我自己的网络服务器上。经过几个月没有遇到麻烦,几天前我遇到了这个错误。我尝试将链接切换到另一个网站,看看它是否是请求模块的错误,但其他网站工作正常。有没有可能我被禁止以这种方式访问​​他们的网站?我仍然可以通过浏览器访问它。或者他们是我没有想到的另一个潜在问题?这是堆栈跟踪。

Traceback (most recent call last):
File "C:\Program Files\Python36\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Program Files\Python36\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Program Files\Python36\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Program Files\Python36\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Program Files\Python36\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Program Files\Python36\lib\http\client.py", line 964, in send
self.connect()
File "C:\Program Files\Python36\lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\Program Files\Python36\lib\ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:\Program Files\Python36\lib\ssl.py", line 808, in __init__
self.do_handshake()
File "C:\Program Files\Python36\lib\ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:\Program Files\Python36\lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Philip Naida/Google Drive/Projects/WeatherDataCollector/WeatherDataCollector v_5.0/WeatherDataCollector.py", line 15, in <module>
source = urllib.request.urlopen('https://flightplanning.navcanada.ca/cgi-bin/CreePage.pl?Langue=anglais&NoSession=NS_Inconnu&Page=forecast-observation&TypeDoc=html').read()
File "C:\Program Files\Python36\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\Python36\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Program Files\Python36\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Program Files\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Program Files\Python36\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Program Files\Python36\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

如果可以的话,你们中的任何人都可以尝试使用 urllib 访问此网页,看看会发生什么吗?任何帮助将不胜感激我想让我的服务器重新联机。

谢谢

最佳答案

查看 report from SSLLabs对于这个站点,您会在许多其他警告中看到:

This server's certificate chain is incomplete.

如果您查看更多详细信息,您会发现服务器仅提供叶证书,但未能提供构建到本地根证书的信任链所需的中间证书。

桌面浏览器经常(但不总是)通过尝试自动从其他地方获取丢失的证书来解决此类配置错误的服务器。但是其他应用程序(如 Python、Perl、Java...应用程序)只会失败,因为如果没有丢失的中间证书就无法正确验证证书。

要绕过此服务器,您需要自己提供中间证书。这可以通过这样的请求来完成:

import requests
response = request.get('https://flightplanning.navcanada.ca', verify='mycerts.pem')

mycerts.pem 包含所有缺失的中间证书和您信任的根证书。您可以在 https://pastebin.com/zi5BN2Vt 找到修复与此特定服务器的连接的此类文件。

关于python - SSL:尝试打开 Nav Canada 网站时出现 CERTIFICATE_VERIFY_FAILED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47244944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com