Search code examples
pythonsocketsirc

"NO IDENT RESPONSE" error when connecting to an IRC server


Usually I would attempt something like this with the twisted library, but that isn't available for python 3 - so I attempted it using the sockets library. The code does establish a connection, but the server quickly responds with "no ident response". I don't have much network programming experience, so I would appreciate it if someone could point out the error I'm making here. I'm also quite aware that there are functions/other code that aren't used, or that Ive used inconsistently. I just thought I would paste the entirety of my code here in case its relevant.

import socket

server = "irc.freenode.net"
channel = "put channel here"
nickname = "put nickname here"


def encode(text):
    return text.encode("ascii")


def ping():
    irc_socket.send(encode("PONG :pingis\n"))


def send_message(chan, msg):
    irc_socket.send(encode("PRIVMSG " + chan + " :" + msg + "\n"))


def join_channel(chan):
    irc_socket.send(encode("JOIN " + chan + "\n"))

def login(username='user', realname='Pythonist', hostname='Helena', servername='Server'):
    irc_socket.send(encode("USER %s %s %s %s" % (username, hostname, servername, realname)))
    irc_socket.send(encode("NICK " + nickname))


irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc_socket.connect((server, 6667))
login()
join_channel(channel)

while True:
    buffer = irc_socket.recv(1024)
    msg = str.split(str(buffer))
    if msg[0] == "PING":
        irc_socket.send("PONG %s" % msg[1])
    print(msg)

The code was originally from: http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python and Ive made minor changes.


Solution

  • Teensy tiny little problem that’s causing all the trouble: you’re missing newlines in login. "USER %s %s %s %s" should be "USER %s %s %s %s\n" and "NICK " + nickname should be "NICK " + nickname + "\n". The server looks up your ident and doesn’t find it, and the next step after that is for you to register, but you never send it a complete line, so it keeps waiting… and waiting…