1

I'm working on Python Socket programming and I have a problem with the send() function. I'm following this: Python socket network programming

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

but I get this error:

Traceback (most recent call last):
  File "*.py", line 27, in <module>
    c.send('Thank you for connecting')
TypeError: a bytes-like object is required, not 'str'
2
  • are you on python 3? Commented Oct 28, 2016 at 15:25
  • yes I'm on python 3.5 Commented Oct 28, 2016 at 15:35

1 Answer 1

2

python 3 send takes a bytes object.

https://docs.python.org/3/library/socket.html#socket.socket.send

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.