我刚刚从python 2.x迁移到python 3.x,下面的代码已停止工作。
#self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print "{} wrote:".format(self.client_address[0])
print self.data
words = self.data.split(',') //the problem seems to be here
知道怎么解决这个问题吗?谢谢!
答案 0 :(得分:1)
这是因为python 3中的bytes
与str
不同。 request.recv
为您提供的是bytes
数据。您需要先将其转换为str
,然后将其用于split
。
您可以执行utf-8
解码。所以像 -
self.data.decode('utf-8').split(',') should work.
it uses the 64bit ABI有更详细的解释。