gpt4 book ai didi

python - UnicodeDecodeError : 'utf-8' codec can't decode byte 0xe2 in position 1023: unexpected end of data

转载 作者:行者123 更新时间:2023-12-03 23:36:38 25 4
gpt4 key购买 nike

基本上我已经用 Python 制作了一个 IRC Twitch 机器人,它现在除了加入 channel 之外什么都不做。乒乓循环可以正常工作一段时间,但随后因标题中的错误而停止。我做错了什么?提前致谢。

import re
import socket

HOST = "irc.twitch.tv"
PORT = 6667
NICK = "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")

最佳答案

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

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

使用这个:
response = s.recv(1024).decode('utf-8', 'ignore')

关于python - UnicodeDecodeError : 'utf-8' codec can't decode byte 0xe2 in position 1023: unexpected end of data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53062552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com