0
votes

I'm trying to send a list over a socket connection, but I'm hitting a Can't convert 'bytes' object to str error.

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)

I also tried jsonS = "{}".format(jsonDecoded, 'utf-8') as well as "".join(str(x) for x in jsonDecoded), which gives me the same error. str(jsonDecoded, 'utf-8') doesn't work either.

Any ideas?

Here is the full stacktrace

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
What are lines 330-350 in websocket\__init__.py? You might have an outdated package. What happens if you take a newer one from the Github repo? - Veedrac
Thanks! That fixed it! - boortmans

1 Answers

0
votes

The package is not up to date. Please update to the newest version from the Github repo.