Python Forum
Problems converting bytes from socket.recvfrom
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems converting bytes from socket.recvfrom
#1
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?
Reply
#2
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020