Python BOM error in Ascii file
Asked Answered
P

1

5

I have a weird, annoying problem with Python 2.6. I'm trying to run this file (and the other), on my Embedded Linux ARM board. http://svn.tuxisalive.com/software_suite_v3/smart-core/smart-server/trunk/TDSService.py

I get this error:

File "tuxhttpserver.py", line 1 SyntaxError: encoding problem: with BOM

I know that error is about the BOM bytes etc etc. BUT, there are NO BOM bytes, it's plain Ascii. I checked with a Hexeditor, and the linux File command says its Ascii.

Im freaking out here... The code worked fine on my Sheevaplug (also a ARM based system).

Parmesan answered 28/4, 2010 at 12:11 Comment(0)
J
10

Don't get too hung up on the "with BOM" remark. It's probably not relevant. What this error usually means is that the Python you are trying to run in does not support the encoding you declare. Observe:

% head -1 tmp.py
# -*- coding: asdfasdfasdf -*-
% python tmp.py
  File "tmp.py", line 1
SyntaxError: encoding problem: with BOM

The Python installation you are running on this Embedded Linux ARM board probably lacks the 'latin-1' encoding. Since you don't have any non-ASCII characters in your source file, just declare the encoding as 'ascii', or leave out the encoding altogether.

Japeth answered 28/4, 2010 at 12:18 Comment(3)
If i change the Latin1 to ascii, it makes no difference. If i remove the line, i get the same error, but in the 'import version' line.Parmesan
Then I guess the Python installation you run on has no encodings what so ever. The fact that you get the error on the 'import version' line probably means the 'version' module has an encoding header as well. I would invest some time to make at least some encodings work on this Python installation.Japeth
This appears to no longer be a correct answer for recent Python releases (in that the specific coding header given as a sample here now reports SyntaxError: encoding problem: asdfasdfasdf, without the BOM claim). The error message only occurs if the coding header doesn't spell out utf-8 but a UTF-8 BOM is present.Stiltner

© 2022 - 2024 — McMap. All rights reserved.