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)