Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Typeerror:代码需要类似字节的对象,而不是'str'-python3.6_Python 3.x - Fatal编程技术网

Python 3.x Typeerror:代码需要类似字节的对象,而不是'str'-python3.6

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

我想使发送字符串“hello”的客户端出错 对于tcp客户端:

    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”