Python - a bytes like object is required, not str

PythonPython 3.xIrcTwitch

Python Problem Overview


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

Python Solutions


Solution 1 - Python

try

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

instead of

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionspencermehtaView Question on Stackoverflow
Solution 1 - PythonvalentinView Answer on Stackoverflow