Hacker News new | past | comments | ask | show | jobs | submit login

isn't the correct practice to use errors="surrogateescape" for precisely this purpose with any encoding? So in this case, you would use .decode("ascii", errors="surrogateescape") as the first bytes are the only ones you are sure of, and then .encode("ascii", errors="surrogateescape") to save again

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact