简体   繁体   English

python错误TypeError:需要一个类似字节的对象,而不是'str'

[英]python error TypeError: a bytes-like object is required,not 'str'

connectionSocket.send("%s\r\n%s\r\n\r\n" %(first_header.encode(encoding='utf_8'), following_header.encode(encoding='utf_8')))

在此处输入图片说明

You are still sending a str string object, because you used a string template (interpolating b'...' byte literal syntax into it).您仍在发送str字符串对象,因为您使用了字符串模板(将b'...'字节文字语法插入其中)。

Encode the result of the str % (params) operation instead:改为对str % (params)操作的结果进行编码:

data = "%s\r\n%s\r\n\r\n" % (first_header, following_header)
connectionSocket.send(data.encode(encoding='utf_8'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python错误:TypeError:需要一个类似字节的对象,而不是'str' - Python error: TypeError: a bytes-like object is required, not 'str' Python 错误类型错误:需要类似字节的 object,而不是“str” - Python ERROR TypeError: a bytes-like object is required, not 'str' Python SocketServer 错误:TypeError:需要类似字节的对象,而不是“str” - Python SocketServer Error : TypeError: a bytes-like object is required, not 'str' 需要一个类似字节的对象,而不是'str':TypeError - a bytes-like object is required, not 'str' : TypeError TypeError:需要一个类似字节的对象,而不是“str” - TypeError: a bytes-like object is required, not 'str' TypeError:需要类似字节的 object,而不是“str”? - TypeError: a bytes-like object is required, not 'str'? TypeError:需要一个类似字节的对象,而不是'str' - TypeError: a bytes-like object is required, not 'str' TypeError:需要一个类似字节的对象,对于无服务器和Python3来说不是'str' - TypeError: a bytes-like object is required, not 'str' with serverless and Python3 Python 3,TypeError:需要一个类似字节的对象,而不是'str' - Python 3, TypeError: a bytes-like object is required, not 'str' Python3 TypeError:需要一个类似字节的对象,而不是“str” - Python3 TypeError: a bytes-like object is required, not 'str'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM