我的 irc 机器人卡在:calvino.freenode.net“注意 * :* 正在查找您的主机名...”在我向代码中添加一些功能之前它就可以工作了。我已经将这些功能注释掉了,但它仍然不起作用! 它停留在该消息上,没有进展。我必须强制它退出。
我是一个非常新手的编码员,大约两周前我才开始编码。所以我完全有可能在某个地方犯了一个非常愚蠢的错误。 作为引用,我使用这篇文章编写了我的机器人的框架。 http://ubuntuforums.org/showpost.php?p=9363159&postcount=3 我没有发布其余的代码,但我已将其放入此粘贴箱中,以备需要时使用! http://pastebin.com/kVF04UFr
import socket
import urllib2
import httplib
import mechanize
channel = '#testbot'
botnick = 'tastybot'
network = 'irc.freenode.net'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK' + botnick + ':\r\n' )
irc.send ( 'USER tastybot tastybot tastybot :Python IRC\r\n' )
irc.send ( 'JOIN' + channel + ':\r\n' )
irc.send ( 'PRIVMSG' + channel + ':What\'s up?\r\n' )
running = True
[various functions]
while running:
[rest of code]
最佳答案
我的猜测是,您要连接的 IRC 服务器需要提供一个 ident:
Ident is an old protocol that servers used to identify which user on a shared system was connecting to them. Nowadays, it is most often used to weed out clones and floodbots from compromised machines (which usually don't have identd [the ident daemon] installed).
来源:http://help.undernet.org/faq.php#19
最简单的解决方法是尝试连接到另一个 IRC 服务器,您可以尝试使用“holmes.freenode.net”作为您的服务器。我在该服务器上使用 IRC 机器人没有遇到任何问题。
编辑: 如果您想查看我用于连接服务器的代码:connection.py
关于python - 为什么我的 Python ircbot 停在 NOTICE * :*** Looking up your hostname. .. 并且不会加入 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9551409/