简体   繁体   中英

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).

Encode the result of the str % (params) operation instead:

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

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