Mohammad Taghi Ghandili Mohammad Taghi Ghandili - 6 months ago 56
Python Question

sending a message by socket in python

I'm working on Python Socking programming and i have a problem with send() function.
Im following this:

# send a thank you message to the client.
c.send('Thank you for connecting')
# Close the connection with the client

but i will get this error:

Traceback (most recent call last):
File "*.py", line 27, in
c.send('Thank you for connecting')
TypeError: a bytes-like object is required, not 'str'


python 3 send takes a bytes object.

c.send(b'Thank you for connecting')