Cant connect to IRC with python?

Hey guys, I want to build my own twitch bot, therefore i tried to connect my account to irc with python.

The problem is, that I get this error message:

Traceback (most recent call last):
  File "C:\Users\kramm\OneDrive\Desktop\ChatBotTwitch\main.py", line 21, in <module>
    irc.connect(('irc.twitch.tv', 6697))
  File "C:\Users\kramm\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1375, in connect
    self._real_connect(addr, False)
  File "C:\Users\kramm\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1353, in _real_connect
    self._sslobj = self.context._wrap_socket(
ssl.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:801)

I have following code:

import ssl
import toml
import socket


def send(irc: ssl.SSLSocket, message: str):
    irc.send(bytes(f"{message}\r\n", "UTF-8"))


if __name__ == "__main__":
    config = toml.load("config.toml")

    bot_username = config["bot_username"]
    channel_name = config["channel_name"]
    oauth_token = config["oauth_token"]

    socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    irc = context.wrap_socket(socket)

    irc.connect(('irc.chat.twitch.tv', 6697))

    send(irc, f"PASS oauth:{oauth_token}")
    send(irc, f"NICK {bot_username}")
    send(irc, f"JOIN #{channel_name}")

    while True:
        data = irc.recv(1024)
        raw_massage = data.decode("UTF-8")

        for line in raw_massage.splitlines():
            print(line)

PROTOCOL_TLS_SERVER suggests some sort of SSL issues.

Could be the time on your computer is wrong or could be any number of things preventing SSL working corrected for your instal

hey thank you for your answer! I found the problem on myself.

The actual problem was the Python Version.

You need Python 3.9 for this

installing a new version of a thing (in this case pythong) (and/or just updating) will also update the curl cert bundles (usually). So it might have been that.

But good to hear