Python 3.x Typeerror:代码需要类似字节的对象,而不是'str'-python3.6
我想使发送字符串“hello”的客户端出错 对于tcp客户端:Python 3.x Typeerror:代码需要类似字节的对象,而不是'str'-python3.6,python-3.x,Python 3.x,我想使发送字符串“hello”的客户端出错 对于tcp客户端: from socket import* servername ='localhost' serverport=12000 while(1): clientsocket=socket(AF_INET,SOCK_STREAM) clientsocket.connect((servername,serverport)) s
from socket import*
servername ='localhost'
serverport=12000
while(1):
clientsocket=socket(AF_INET,SOCK_STREAM)
clientsocket.connect((servername,serverport))
sentence=input("Input sentence:")
clientsocket.send(sentence)
ModifiedSentence = clientsocket.recv(1024)
print ('From Server:', ModifiedSentence)
clientsocket.close()
请添加完整错误,是哪一行引起的?在python3中,字符串是unicode对象,字节对象在字符串b'foo'前面写有一个b。如果您有一个字符串并且需要一个字节对象,则需要对其进行编码。回溯最近的调用last:file,第6行,在typeError中:需要一个类似字节的对象,而不是“str”