{"id":988,"hash":"e0530a70af96249740592eeed2629167a2f6de3669f199ab2beb7cb6b088344f","pattern":"ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)","full_message":"I was playing with some web frameworks for Python, when I tried to use the framework aiohhtp with this code (taken from the documentation):\n\nimport aiohttp\nimport asyncio\n\n#********************************\n# a solution I found on the forum:\n# https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org?rq=1\nimport ssl\nssl._create_default_https_context = ssl._create_unverified_context\n# ... but it doesn't work :(\n#********************************\n\nasync def main():\n\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\"https://python.org\") as response:\n\n            print(\"Status:\", response.status)\n            print(\"Content-type:\", response.headers[\"content-type\"])\n\n            html = await response.text()\n            print(\"Body:\", html[:15], \"...\")\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n\nWhen I run this code I get this traceback:\n\nDeprecationWarning: There is \nno current event loop\n  loop = asyncio.get_event_loop()\nTraceback (most recent call last):\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 986, in _wrap_create_connection\n    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa\n  File \"c:\\Python310\\lib\\asyncio\\base_events.py\", line 1080, in create_connection\n    transport, protocol = await self._create_connection_transport(\n  File \"c:\\Python310\\lib\\asyncio\\base_events.py\", line 1110, in _create_connection_transport\n    await waiter\n  File \"c:\\Python310\\lib\\asyncio\\sslproto.py\", line 528, in data_received\n    ssldata, appdata = self._sslpipe.feed_ssldata(data)\n  File \"c:\\Python310\\lib\\asyncio\\sslproto.py\", line 188, in feed_ssldata\n    self._sslobj.do_handshake()\n  File \"c:\\Python310\\lib\\ssl.py\", line 974, in do_handshake\n    self._sslobj.do_handshake()\nssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)    \n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"c:\\Users\\chris\\Documents\\Programmi_in_Python_offline\\Esercitazioni\\Python_commands\\aioWebTest.py\", line 21, in <module>   \n    loop.run_until_complete(main())\n  File \"c:\\Python310\\lib\\asyncio\\base_events.py\", line 641, in run_until_complete\n    return future.result()\n  File \"c:\\Users\\chris\\Documents\\Programmi_in_Python_offline\\Esercitazioni\\Python_commands\\aioWebTest.py\", line 12, in main       \n    async with session.get(\"https://python.org\") as response:\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\client.py\", line 1138, in __aenter__\n    self._resp = await self._coro\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\client.py\", line 535, in _request\n    conn = await self._connector.connect(\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 542, in connect\n    proto = await self._create_connection(req, traces, timeout)\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 907, in _create_connection\n    _, proto = await self._create_direct_connection(req, traces, timeout)\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 1206, in _create_direct_connection\n    raise last_exc\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 1175, in _create_direct_connection\n    transp, proto = await self._wrap_create_connection(\n  File \"c:\\Python310\\lib\\site-packages\\aiohttp\\connector.py\", line 988, in _wrap_create_connection\n    raise ClientConnectorCertificateError(req.connection_key, exc) from exc\naiohttp.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)')]\n\nFrom 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:\n\nCOMODO ECC Certification Authority;\nthree certificates that I took from the site www.python.org under Bango's advice for the question:\n\nI'm sorry for the long question, but I searched a lot on the internet and I couldn't find the solution for my case.\nThank you in advance, guys <3","ecosystem":"pypi","package_name":"python-3.x","package_version":null,"solution":"Picking up on the comment by @salparadise, the following worked for me:\n\nsession.get(\"https://python.org\", ssl=False)\n\nEdit (2023-03-10):\n\nI've run into this problem again and have found this answer to a similar question, which provides a much better long-term solution.\n\nIn short: use the certificates in the certifi package to create the aiohttp client session (as @salparadise also suggested earlier). You'll find the code to do so at the link above. It worked for me just as well as disabling ssl, and is of course a much better way of solving the problem.","confidence":0.8,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/70236730/ssl-sslcertverificationerror-ssl-certificate-verify-failed-certificate-verif","votes":11,"created_at":"2026-04-19T04:52:07.358808+00:00","updated_at":"2026-04-19T04:52:07.358808+00:00"}