Avatar ·

Encoding error in Python: readline() when reading utf-8 file complains: 'charmap' codec can't decode byte

📁 строка, python, ии

I'm trying to read the IANA ports file. It is saved in UTF-8 w/o BOM encoding. But on one of the lines, the readline() function complains like this:

'charmap' codec can't decode byte 0x98 in position 7938: character maps to <""undefined"">

The line in the file looks like this:

# Jim Harlan <""jimh&infowest.com"">

What workaround can I come up with for this? Or is there a direct solution?

UPD

A workaround in the form of deleting this line will work (and it's somehow the only one like this), but only for debugging, because later, if something happens, partners will be pulling hair out of my head. I'll also post the code I'm using for this operation: