簡體   English   中英

Python-需要像對象這樣的字節,而不是str

[英]Python - a bytes like object is required, not str

我將Twitch機器人從Python 2.7移到了Python 3.5。 我不斷收到錯誤消息:在下面代碼的第二行上, a bytes like object is required not 'str'

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM