【发布时间】:2014-08-03 21:45:29
【问题描述】:
我正在尝试通过套接字连接发送列表,但遇到Can't convert 'bytes' object to 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
【问题讨论】:
-
websocket\__init__.py中的第 330-350 行是什么?你可能有一个过时的包。如果您从 Github 存储库中获取更新的版本会怎样? -
谢谢!这解决了它!