Hi All,
While playing around with the code / rewriting my own way, I encountered an error similar to the one mentioned here, however, I got a UnicodeDecodeError.
UnicodeDecodeError: ‘utf-16-le’ codec can’t decode bytes in position 812-813: illegal UTF-1UTF-16 surrogate
When I reviewed the code with the original one, I found that I made a mistake while opening the file.
lang = open(“files/languages.txt”, encoding=enc_form)
So instead of explicitly mentioning encoding = “utf-8”
, I used it with the one mentioned in command line (‘enc_form’ was unpacked with argv).
In the above scenario, the output was perfect when using utf-8 and error appeared when I used utf-16. I think I am missing the logic. My question is, why are we hard-coding utf-8 there? Is it because the file was saved as utf-8 format or because Python sees everything as utf-8? Also when I googled the error, someone mentioned to use iso-8859-1 (whatever it is!) but that didn’t help at all. Please help.
Thank you.