"UnicodeError: UTF-16 stream does not start with BOM" when opening a file that appears to have a BOM

I have a project where most of the files are UTF-16, but one of them is UTF-8. After putting the correct encoding ("utf_8" or "utf_16") in strOpenEncoding, I tried this:

for strInput in open(strInputFileName, "r", newline="\n", encoding=strOpenEncoding):

      

I get this answer:

UnicodeError: UTF-16 stream does not start with BOM

      

I opened the file it is trying to manually open and it definitely contains a byte mark and definitely UTF-16. What am I doing wrong?

+3


source to share





All Articles