简体   繁体   中英

Python TypeError: can't concat bytes to str

I am trying to sending a data with socket and I am having problem named "builtins.TypeError: can't concat bytes to str" .

It's the packet I am trying to send:

pack('!i', int(0))+pack('!b', int(this.lastPacketID))+pack('!h', int(2))+"br"+pack('!h', int(2))+"br"+pack('!i', int(this.authKey))+pack('!i', int(this.authKeyLogin))

"br" is a string, and pack returns a bytes object. replace "br" with b"br" and it should work

pack()返回一个字节对象,而"br"是一个字符串对象,通常您需要编码一个字符串以将其转换为字节,但是在您的情况下,您可以通过使python将"br"视为字节来解决此问题: b"br"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM