title: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)
body: <p>I was playing with some web frameworks for Python, when I tried to use the framework <a href="https://docs.aiohttp.org/en/stable/" rel="nofollow noreferrer">aiohhtp</a> with this code (taken from the documentation):</p>
  <pre><code>import aiohttp
  import asyncio
  
  #********************************
  # a solution I found on the forum:
  # https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org?rq=1
  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(&quot;https://python.org&quot;) as response:
  
              print(&quot;Status:&quot;, response.status)
              print(&quot;Content-type:&quot;, response.headers[&quot;content-type&quot;])
  
              html = await response.text()
              print(&quot;Body:&quot;, html[:15], &quot;...&quot;)
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(main())
  </code></pre>
  <p>When I run this code I get this traceback:</p>
  <pre><code>DeprecationWarning: There is 
  no current event loop
    loop = asyncio.get_event_loop()
  Traceback (most recent call last):
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, line 986, in _wrap_create_connection
      return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
    File &quot;c:\Python310\lib\asyncio\base_events.py&quot;, line 1080, in create_connection
      transport, protocol = await self._create_connection_transport(
    File &quot;c:\Python310\lib\asyncio\base_events.py&quot;, line 1110, in _create_connection_transport
      await waiter
    File &quot;c:\Python310\lib\asyncio\sslproto.py&quot;, line 528, in data_received
      ssldata, appdata = self._sslpipe.feed_ssldata(data)
    File &quot;c:\Python310\lib\asyncio\sslproto.py&quot;, line 188, in feed_ssldata
      self._sslobj.do_handshake()
    File &quot;c:\Python310\lib\ssl.py&quot;, 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 &quot;c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py&quot;, line 21, in &lt;module&gt;   
      loop.run_until_complete(main())
    File &quot;c:\Python310\lib\asyncio\base_events.py&quot;, line 641, in run_until_complete
      return future.result()
    File &quot;c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py&quot;, line 12, in main       
      async with session.get(&quot;https://python.org&quot;) as response:
    File &quot;c:\Python310\lib\site-packages\aiohttp\client.py&quot;, line 1138, in __aenter__
      self._resp = await self._coro
    File &quot;c:\Python310\lib\site-packages\aiohttp\client.py&quot;, line 535, in _request
      conn = await self._connector.connect(
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, line 542, in connect
      proto = await self._create_connection(req, traces, timeout)
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, line 907, in _create_connection
      _, proto = await self._create_direct_connection(req, traces, timeout)
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, line 1206, in _create_direct_connection
      raise last_exc
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, line 1175, in _create_direct_connection
      transp, proto = await self._wrap_create_connection(
    File &quot;c:\Python310\lib\site-packages\aiohttp\connector.py&quot;, 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)')]
  </code></pre>
  <p>From the final row I have thought that it was a problem with a certificate that is expired, so I searched on the internet and I tried to solve installing some certificates:</p>
  <ul>
  <li><a href="https://crt.sh/?id=2835394" rel="nofollow noreferrer">COMODO ECC Certification Authority</a>;</li>
  <li>three certificates that I took from the site <a href="https://www.python.org" rel="nofollow noreferrer">www.python.org</a> under <a href="https://stackoverflow.com/users/4445768/bango">Bango</a>'s advice for the <a href="https://stackoverflow.com/questions/63742983/certificate-verify-failed-certificate-has-expired-ssl-c-when-attempti">question</a>:<img src="https://i.postimg.cc/85YsRrw3/immagine-2021-12-05-181731.png" alt="" /></li>
  </ul>
  <p>I'm sorry for the long question, but I searched a lot on the internet and I couldn't find the solution for my case.
  Thank you in advance, guys &lt;3</p>