'Connection reset by peer' error with a really simply Python3 IRC client


I am having a problem with my program. I am trying to write the simplest Python 3 IRC client which just connects to a channel and receives messages sent to that channel. A lot of this is cribbed from other people on here/github and so should be mostly sensible but I get ‘[Errno 54] Connection reset by peer’ when I try to receive a message and I cannot for the life of my work out why. I have tried my credentials on an online IRC client and was able to connect just fine so I don’t think it is a problem with them.

Can anyone help? The full 26 line program is below. Many thanks!

import socket
import sys
import string

server = "irc.chat.twitch.tv"
port = 6667
channel = "{a_channel_name_all_lowercase}"
nick = "{my_name_all_lowercase}"
password = "{oauth:some_token}"

irc = socket.socket() 
print("connecting to: "+ server)
irc.connect((server, port)) 

irc.send(bytes("PASS " + password + "\r\n", "UTF-8"))
irc.send(bytes("NICK "+ nick +"\n", "UTF-8"))
irc.send(bytes("JOIN #"+ channel +"\n", "UTF-8"))

irc.send(("PRIVMSG #" + channel + " : Hello\r\n").encode("utf-8"))

while 1:   
   message = irc.recv(2048).decode('utf-8') 
   if(message != ""):
   	print("Msge: " +  message)
   	if message == "PING :tmi.twitch.tv\r\n":
   		s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))

Hi all,

It turns out that the problem was that the uni I am working from is either blocked from talking to twitch or twitch is blocked by it. This program works fine when connected to a different network!

You can also try connecting to port 80 as apposed to the traditional IRC ports

im not sure how python works, but you might also want to wait to receive the welcome message before your join statement. after pass and nick, wait ttil you get that twisty maze stuff.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.