TypeError - Client error in python

前端 未结 2 1207
孤独总比滥情好
孤独总比滥情好 2021-01-23 00:59

I created a Client/Server code in python. Server works well and get listen on 8000 port, but when I connect to it via client and then I try to send a message to server I get the

相关标签:
2条回答
  • 2021-01-23 01:19

    The python 2 documentation for the sockets class shows the .send function/method accepting a string parameter - but if you look at the python 3 documentation for the same class you'll see that .send now requires the data to be passed as a parameter of type bytearray.

    Changing:

    sendData = str(input("Client : "))
    

    to

    sendData = str.encode(input("Client : "))
    

    should do the trick, I believe.

    0 讨论(0)
  • 2021-01-23 01:28
        TcpSocket.send(sendData)
    

    Looks like send accepts only bytes instances. Try:

        TcpSocket.send(bytes(sendData, "ascii")) #... or whatever encoding is appropriate
    
    0 讨论(0)
提交回复
热议问题