Python Forum

Full Version: Problems converting bytes from socket.recvfrom
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to convert bytes from the recvfrom function to text but i get this error:
Error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xac in position 4: invalid start byte
with different byte that gives the error.

The code I'm using is
import socket
import time

import struct
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)

while a:
    raw_data, addr = s.recvfrom(65565)
    print(raw_data.decode("utf-8"))
Can someone help?
The other side may be sending something that's different from utf8-encoded unicode. The solution is to know exactly what kind of data the other side of the socket is sending.