为了账号安全,请及时绑定邮箱和手机立即绑定

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1023

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1023

海绵宝宝撒 2021-07-30 14:49:00
基本上我已经用 Python 制作了一个 IRC Twitch 机器人,它现在除了加入频道之外什么都不做。乒乓循环可以正常工作一段时间,但随后因标题中的错误而停止。我做错了什么?提前致谢。import reimport socketHOST = "irc.twitch.tv"PORT = 6667NICK = "asdsad"PASS = "oauth:asdasdasdasd"channel = "#coolperson"def send_message(sock, msg):    sock.send("PRIVMSG #{} {}".format(channel, msg))s = socket.socket()s.connect((HOST, PORT))s.send("PASS {}\r\n".format(PASS).encode("utf-8"))s.send("NICK {}\r\n".format(NICK).encode("utf-8"))s.send("JOIN {}\r\n".format(channel).encode("utf-8"))while True:    response = s.recv(1024).decode("utf-8")    if response == "PING :tmi.twitch.tv\r\n":        s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))        print("answered the call")
查看完整描述

2 回答

?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

您可以跳过该错误。而不是以下部分:

response = s.recv(1024).decode("utf-8")

使用这个:

response = s.recv(1024).decode('utf-8', 'ignore')


查看完整回答
反对 回复 2021-08-03
  • 2 回答
  • 0 关注
  • 193 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号