I am making a chat client to connect to a server I already made with sockets in Python 3, but I am having a problem with the new encoding and decosing stuff for Python 3. Here is the relevant code:
else : # user entered a message msg = sys.stdin.readline() s.send(bytes((msg, 'utf-8'))) sys.stdout.write(bytes('[Me] ')) sys.stdout.flush()
and here is the error I get when running this client from python in terminal:
# It connects to the server fine, as we can see from the next two lines, but if I try to type a message it closes and outputs the error message. Connected to remote host. You can start sending messages [Me] hi Traceback (most recent call last): File "client.py", line 50, in <module> client() File "client.py", line 45, in client s.send(bytes((msg, 'utf-8'))) TypeError: 'str' object cannot be interpreted as an integer
I read this: http://www.pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/ and adjusted my code accordingly, but it still gives me the same error. Please feel free to ask for anything else you may need.