Python - a bytes like object is required, not str

半腔热情 提交于 2019-12-03 08:08:54

问题


I'm moving my Twitch bot from Python 2.7 to Python 3.5. I keep getting the error: a bytes like object is required not 'str' on the 2nd line of the code below.

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

回答1:


try

data = twitchdata.decode().split(":")[1]

instead of

data = twitchdata.split(":")[1]


来源:https://stackoverflow.com/questions/29643544/python-a-bytes-like-object-is-required-not-str

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!