TypeError: a bytes-like object is required, not ‘str’

This code is good for Python 2. But in Python 3, results in bit encoding error. I was trying to make a simple TCP server and encountered the same problem. Encoding solves this. Try this with sendto command.

clientSocket.sendto(message.encode(),(serverName, serverPort))

Similarly you should use .decode() to receive the data on the UDP server side, if you want to print it exactly as it was sent.

Leave a Comment