PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
791 stars 163 forks source link

SSL errors with id.twitch.tv #270

Closed danzek closed 2 years ago

danzek commented 2 years ago

The underlying exception seems to be:

aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host id.twitch.tv:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')]

For some reason twitchio won't work for me anymore due to SSL errors. Is this on Twitch's end? Is it an issue in aiohttp that can't be addressed in twitchio? Or is it just a configuration on my end? This previously worked fine then stopped after my latest OS update to macOS Monterey 12.2.1 so perhaps that's the culprit.

EvieePy commented 2 years ago

Hey, can you try the following for me:

Navigate to your Applications/Python 3.X/ folder and double click the Install Certificates.command.

danzek commented 2 years ago

Hello @EvieePy and thank you for the fast response!

I unfortunately don’t have such a file on my computer. I had seen this on some other forum posts elsewhere also and so even downloaded the Install Certificates.command from the Python GitHub repo but to no avail. I’ve also tried uninstalling and reinstalling certifi, aiohttp, twitchio, and Python itself. None of this seems to work.

danzek commented 2 years ago

@EvieePy this issue was just confined to me. I deleted my entire virtual environment for this project and rebuilt it and now it works fine. Thanks for your help!

ThatsAMorais commented 2 years ago

Hi! I am seeing this same exact error, suddenly, starting Thursday or Friday.

Traceback (most recent call last):
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/twitchio/client.py", line 178, in connect
    await self._connection._connect()
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/twitchio/websocket.py", line 128, in _connect
    data = await self._client._http.validate(token=self._token)
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/twitchio/http.py", line 318, in validate
    async with self.session.get(url, headers=headers) as resp:
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/thatsamorais/.local/share/virtualenvs/twitch-creamery-MpouS0DB/lib/python3.9/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host id.twitch.tv:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')]

I am on Ubuntu v20.x, and these actions did not resolve my issue.

sudo apt-get install ca-certificates
sudo update-ca-certificates --fresh
sudo apt-get remove ca-certificates

Removing the virtual environment as a solution implied by @danzek does not change anything for me, and might not get to the root cause. Following the above steps, I tried this again, but I am not seeing a change.

Could you elaborate a little on whether there is an analogous action I can take to accomplish "Install Certificates.command" in linux? I believe that is an OS X solution.

Add'l random stuff I tried:

I was setting up certbot and nginx so I could run an eventsub webhook callback, and when I went to test, all of my bots emit this error.

Thank you for your time!

chillymosh commented 2 years ago

@ThatsAMorais I'd recommend joining the discord to discuss this further but may I ask what you are importing into your bot? Would you happen to be using a MySQL lib?

ThatsAMorais commented 2 years ago

I should join the discord, thank you! I assume the link is somewhere on the repo home page?

Can confirm that I am not using a MySQL lib, as I do not yet have any database integrations.

Thank you for your quick reply!

ThatsAMorais commented 2 years ago

After downgrading my pipenv python version to 3.8 from 3.9.9 it fixed my issue.

danzek commented 2 years ago

Some potentially helpful links:

https://stackoverflow.com/a/58394602/868044

https://stackoverflow.com/a/70834894/868044

https://stackoverflow.com/a/70180553/868044

I think I also uninstalled and reinstalled the certifi lib via pip while diagnosing my issue as well, but only rebuilding my virtual environment altogether ultimately resolved my issue.