![](/img/trans.png)
[英]Python error: TypeError: a bytes-like object is required, not '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')))
您仍在发送str
字符串对象,因为您使用了字符串模板(将b'...'
字节文字语法插入其中)。
改为对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.