在Python 3.5中,使用套接字,我有:
message = 'HTTP/1.1 200 OK\nContent-Type: text/html\n\n'
s.send(message.encode())
Run Code Online (Sandbox Code Playgroud)
我怎么能在一行中做到这一点?我问,因为我有:
s.send('HTTP/1.1 200 OK\nContent-Type: text/html\n\n')
Run Code Online (Sandbox Code Playgroud)
但是在Python中需要3.5个字节,而不是字符串,所以这给出了错误:
builtins.TypeError: a bytes-like object is required, not 'str'
Run Code Online (Sandbox Code Playgroud)
我不应该使用发送吗?