ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)

当我尝试将框架 aiohhtp 与此代码(取自文档)一起使用时,我正在为 Python 使用一些 Web 框架:

import aiohttp
import asyncio

#********************************
# a solution I found on the forum:
# 
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# ... but it doesn't work :(
#********************************

async def main():

    async with aiohttp.ClientSession() as session:
        async with session.get("https://python.org") as response:

            print("Status:", response.status)
            print("Content-type:", response.headers["content-type"])

            html = await response.text()
            print("Body:", html[:15], "...")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

当我 运行 这段代码时,我得到了这个回溯:

DeprecationWarning: There is 
no current event loop
  loop = asyncio.get_event_loop()
Traceback (most recent call last):
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "c:\Python310\lib\asyncio\base_events.py", line 1080, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "c:\Python310\lib\asyncio\base_events.py", line 1110, in _create_connection_transport
    await waiter
  File "c:\Python310\lib\asyncio\sslproto.py", line 528, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "c:\Python310\lib\asyncio\sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "c:\Python310\lib\ssl.py", line 974, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)    

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py", line 21, in <module>   
    loop.run_until_complete(main())
  File "c:\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
    return future.result()
  File "c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py", line 12, in main       
    async with session.get("https://python.org") as response:
  File "c:\Python310\lib\site-packages\aiohttp\client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "c:\Python310\lib\site-packages\aiohttp\client.py", line 535, in _request
    conn = await self._connector.connect(
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 988, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host python.org:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')]

从最后一行开始,我以为是证书过期的问题,于是在网上搜索,尝试安装一些证书解决:

很抱歉问了这么长的问题,但我在互联网上搜索了很多,但找不到适合我的情况的解决方案。 提前谢谢大家 <3

根据@salparadise 的评论,以下对我有用:

session.get("https://python.org", ssl=False)