Tuesday, 18 May 2021

Why is socket.io unable to decode the packet send with error `invalid literal for int() with base 10: b'\x00'`?

I am getting this error :

  File "/usr/local/lib/python3.7/dist-packages/engineio/server.py", line 596, in _trigger_event
    return self.handlers[event](*args)
  File "/usr/local/lib/python3.7/dist-packages/socketio/server.py", line 738, in _handle_eio_message
    pkt = packet.Packet(encoded_packet=data)
  File "/usr/local/lib/python3.7/dist-packages/socketio/packet.py", line 41, in __init__
    self.attachment_count = self.decode(encoded_packet)
  File "/usr/local/lib/python3.7/dist-packages/socketio/packet.py", line 82, in decode
    self.packet_type = int(ep[0:1])
ValueError: invalid literal for int() with base 10: b'\x00'

I notice that socket.io unable to decode it on server from what I read on internet there is possibility that because there is integer on my sending packet so I convert it to string as you can see below, but the error keep persisting and who knows this help solve the problem the error did not occur when I test locally using socket.io it only happen when I am hosting it on aws linux server

Here is my Javascript code:

<script type="text/javascript" src=""></script>
<script type="text/javascript" src="" ></script>
<script async type="text/javascript" charset="utf-8">
const FPS = 10
 var socket = io('url');
 setInterval(() => {
             var type = "image/png"
             var video_element = document.getElementById("videoElement")
             var frame = capture(video_element, 1)
             var data = frame.toDataURL(type);
             console.log(data)
             data = data.replace('data:' + type + ';base64,', '');
             data = String(data)
             socket.emit('image', data);
          }, 1000/FPS );
</script>

Here is my python code in case needed thought I think it is irrelevant in this case since it happen when socket.io is emitting from client to server

@socketio.on('image')
def image(data_image):

    sbuf = StringIO()
    sbuf.write(data_image)
    

    b = io.BytesIO(base64.b64decode(data_image))
    if(str(data_image) == 'data:,'):
        pass
    else:
    
    #process the image for object detetection
    
    imgencode = cv2.imencode('.jpg', frame)[1]

    stringData = base64.b64encode(imgencode).decode('utf-8')
    b64_src = 'data:image/jpg;base64,'
    stringData = b64_src + stringData
    emit('response_back', stringData)

EDIT:
python-socketio = 5.1.0
javascript Socket.Io = 4.0



from Why is socket.io unable to decode the packet send with error `invalid literal for int() with base 10: b'\x00'`?

No comments:

Post a Comment