python3 - 无法隐式将 'bytes' 对象转换为 str
我正在尝试通过套接字连接发送一个列表,但遇到了一个错误,提示 无法将 'bytes' 对象转换为 str
。
while True:
try:
data = stream.read(CHUNK)
except IOError:
pass
else:
decoded = numpy.fromstring(data, dtype=numpy.float32)
i = json.dumps(decoded.tolist())
jsonDecoded = json.loads(i)
jsonS = "%s" % jsonDecoded
ws.send(jsonS)
我还尝试过 jsonS = "{}".format(jsonDecoded, 'utf-8')
和 "".join(str(x) for x in jsonDecoded)
,结果也出现了同样的错误。str(jsonDecoded, 'utf-8')
也不行。
有没有什么建议?
这是完整的错误追踪信息
Traceback (most recent call last):
File "C:\Users\Bart\Dropbox\Redux\streaming\streaming\streamingdata.py", line 39, in <module>
ws.send(jsonS)
File "C:\Python33\lib\site-packages\websocket_client_py3-0.14.1-py3.3.egg\websocket\__init__.py", line 655, in send
return self.send_frame(frame)
File "C:\Python33\lib\site-packages\websocket_client_py3-0.14.1-py3.3.egg\websocket\__init__.py", line 674, in send_frame
data = frame.format()
File "C:\Python33\lib\site-packages\websocket_client_py3-0.14.1-py3.3.egg\websocket\__init__.py", line 340, in format
frame_header += struct.pack("!H", length)
TypeError: Can't convert 'bytes' object to str implicitly
1 个回答
0
这个软件包不是最新的。请从Github仓库更新到最新版本。