代码:
import socket, feedparser
feed = feedparser.parse("http://pwnmyi.com/feed")
latest = feed.entries[0]
art_name = latest.title
network = 'irc.rizon.net'
port = 6667
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((network, port))
print irc.recv(4096)
irc.send('NICK PwnBot\r\n')
irc.send('USER PwnBot PwnBot PwnBot :PwnBot by Fike\r\n')
irc.send('JOIN #pwnmyi\r\n')
while True:
data = irc.recv(4096)
if data.find('PING') != -1:
irc.send('PONG ' + data.split() [1] + '\r\n')
if data.find( '!latest' ) != -1:
irc.send('PRIVMSG #pwnmyi :Latest Article: ' + art_name + '\r\n')
它连接等等,但是当我在频道中执行 !latest 时,它就这样退出了:
irc.send('PRIVMSG #pwnmyi :Latest Article: ' + art_name + '\r\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 55: ordinal not in range(128)
你能帮我调试这段代码吗?它以前对我有用。