doniyor doniyor - 1 year ago 101
Python Question

python - "SyntaxError: encoding issue: with BOM"

I am trying to run some cronjobs in django.

I have three of them, 2 of them are running flawlessly. but the third one is giving me the error:

../../", line 1
SyntaxError: encoding problem: with BOM

the first 2 lines of this file are:

1. # -*- coding: utf-8 -*-
2. from import BaseCommand, CommandError
3. ...

the other 2 cronjobs are the same as this one. i am stuck - why only this one is complaining? It seems python doesnot support
? it cannot be, right?

Answer Source

According to this page:

you have two options...

To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, such as:

    # coding=<encoding name>

or (using formats recognized by popular editors)

    # -*- coding: <encoding name> -*-

(Note: While the above is a direct quote, @tdelaney pointed out - and I agree - that instead of the fixed path #!/usr/bin/python one should use #!/usr/bin/env python.)

It looks like you're using part of the second option but did not include the required first line ( #!/usr/bin/python ). Try inserting that before your "coding" line and see what happens.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download