Python-需要像对象这样的字节,而不是str [英] Python - a bytes like object is required, not str

查看:71
本文介绍了Python-需要像对象这样的字节,而不是str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Twitch机器人从Python 2.7移到Python 3.5.我不断收到错误: a bytes like object is required not 'str'在下面代码的第二行.

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

推荐答案

尝试

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

代替

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

这篇关于Python-需要像对象这样的字节,而不是str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆