【问题标题】:python3 - Can't convert 'bytes' object to str implicitlypython3 - 无法将'bytes'对象隐式转换为str
【发布时间】: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 存储库中获取更新的版本会怎样?
  • 谢谢!这解决了它!

标签: python string


【解决方案1】:

软件包不是最新的。请从 Github repo 更新到最新版本。

【讨论】:

    猜你喜欢
    • 2018-12-26
    • 2016-04-15
    • 1970-01-01
    • 2017-07-21
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 2017-08-31
    相关资源
    最近更新 更多