我正在将我的 Twitch 机器人从 Python 2.7 迁移到 Python 3.5。我不断收到错误:
a bytes like object is required not 'str'
在下面代码的第 2 行。
twitchdata = irc.recv(1204)
data = twitchdata.split(":")[1]
twitchuser = data.split("!")[0]
twitchmsg = twitchdata.split(":")[2]
chat = str(twitchuser) +": "+ str(twitchmsg)
print(chat) #prints chat to console
最佳答案
试试
data = twitchdata.decode().split(":")[1]
而不是
data = twitchdata.split(":")[1]
关于Python - 需要像对象这样的字节,而不是 str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29643544/