我不知道我在做什么错。没有错误或任何东西,它只是说我没有注册。这也是一个IRC channel 和网络,不需要注册刻痕即可使用。提前致谢。
#I've set variables and imported stuff up here
socket.connect((host, port))
socket.recv(512)
socket.send('NICK %s' % (username))
socket.send('USER %s %s %s :%s\r\n' % (username, username, username, username))
pingPong = socket.recv(512)
print pingPong
pingPong = pingPong[5:]
print 'PONG ' + pingPong
socket.send('PONG %s\r\n' % pingPong)
print 'PONG ' + host + '\r\n'
time.sleep(5) #I even added this time.sleep() to wait for the PONG to go through.
socket.send('JOIN %s\r\n' % channel)
socket.recv(1024)
#I have a while loop that continually receives data and commands down here
输出:
平:912E235B
乒乓:912E235B
:irc.va.us.mibbit.net 451 JOIN:您尚未注册
最佳答案
您的NICK和USER命令格式错误。 NICK的末尾应带有“\r\n”。 USER不仅应该是您的用户名4次。以下是与该irc服务器的有效连接。
import socket
host = "irc.va.us.mibbit.net"
port = 6667
username = "andrew"
channel = "luck"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
print "recv 1", s.recv(512)
s.send('NICK %s\r\n' % (username,))
s.send('USER %s 8 * :%s\r\n' % (username, username))
pingPong = s.recv(512)
print "recv 2", pingPong
pingPong = pingPong[5:]
s.send('PONG %s\r\n' % pingPong)
s.send('JOIN %s\r\n' % (channel,))
msg = s.recv(1024)
print "Message", msg
关于python - IRC bot无法连接到服务器-Python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25457942/