TypeError - Client error in python

前端 未结 2 1208
孤独总比滥情好
孤独总比滥情好 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.

提交回复
热议问题