Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > SyntaxError: encoding problem: with BOM

Reply
Thread Tools

SyntaxError: encoding problem: with BOM

 
 
NoName
Guest
Posts: n/a
 
      12-24-2008
i have 1.py in cp866 encoding:

# -*- coding: cp866 -*-
print ("ff")



It's not work in Python 3.0
Error:

File "<decoding error>", line 1
SyntaxError: encoding problem: with BOM

what's wrong?
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      12-24-2008
NoName schrieb:
> i have 1.py in cp866 encoding:
>
> # -*- coding: cp866 -*-
> print ("ff")
>
>
>
> It's not work in Python 3.0
> Error:
>
> File "<decoding error>", line 1
> SyntaxError: encoding problem: with BOM
>
> what's wrong?


I can only guess, but just because you write the coding-header that
doesn't mean that the editor you use does actually *use* that encoding.
What I presume it does is to use utf-8, and write that stupid BOM
microsoft uses for denoting utf-8-content as first byte. Try using a
different editor, or alter it's settings to really use your desired
encoding.

Diez
 
Reply With Quote
 
 
 
 
NoName
Guest
Posts: n/a
 
      12-24-2008
On 25 , 00:37, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
> NoName schrieb:
>
> > i have 1.py in cp866 encoding:

>
> > # -*- coding: cp866 -*-
> > print ("ff")

>
> > It's not work in Python 3.0
> > Error:

>
> > File "<decoding error>", line 1
> > SyntaxError: encoding problem: with BOM

>
> > what's wrong?

>
> I can only guess, but just because you write the coding-header that
> doesn't mean that the editor you use does actually *use* that encoding.
> What I presume it does is to use utf-8, and write that stupid BOM
> microsoft uses for denoting utf-8-content as first byte. Try using a
> different editor, or alter it's settings to really use your desired
> encoding.
>
> Diez


I used Far Manager editor. and it *really* used cp866
I can print hex dump of source file.
I don't want to use UTF-8 for py-file!
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      12-24-2008
NoName schrieb:
> On 25 , 00:37, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
>> NoName schrieb:
>>
>>> i have 1.py in cp866 encoding:
>>> # -*- coding: cp866 -*-
>>> print ("ff")
>>> It's not work in Python 3.0
>>> Error:
>>> File "<decoding error>", line 1
>>> SyntaxError: encoding problem: with BOM
>>> what's wrong?

>> I can only guess, but just because you write the coding-header that
>> doesn't mean that the editor you use does actually *use* that encoding.
>> What I presume it does is to use utf-8, and write that stupid BOM
>> microsoft uses for denoting utf-8-content as first byte. Try using a
>> different editor, or alter it's settings to really use your desired
>> encoding.
>>
>> Diez

>
> I used Far Manager editor. and it *really* used cp866
> I can print hex dump of source file.
> I don't want to use UTF-8 for py-file!


How about you show us the python file in question?

diez
 
Reply With Quote
 
NoName
Guest
Posts: n/a
 
      12-25-2008
On 25 дек, 03:35, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
> NoName schrieb:
>
>
>
> > On 25 ÄÅË, 00:37, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
> >> NoName schrieb:

>
> >>> i have 1.py in cp866 encoding:
> >>> # -*- coding: cp866 -*-
> >>> print ("ff")
> >>> It's not work in Python 3.0
> >>> Error:
> >>> File "<decoding error>", line 1
> >>> SyntaxError: encoding problem: with BOM
> >>> what's wrong?
> >> I can only guess, but just because you write the coding-header that
> >> doesn't mean that the editor you use does actually *use* that encoding..
> >> What I presume it does is to use utf-8, and write that stupid BOM
> >> microsoft uses for denoting utf-8-content as first byte. Try using a
> >> different editor, or alter it's settings to really use your desired
> >> encoding.

>
> >> Diez

>
> > I used Far Manager editor. and it *really* used cp866
> > I can print hex dump of source file.
> > I don't want to use UTF-8 for py-file!

>
> How about you show us the python file in question?
>
> diez


you can get it here http://slil.ru/26481345
 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      12-25-2008
On Dec 25, 11:36*pm, NoName <(E-Mail Removed)> wrote:
> On 25 дек, 03:35, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
>
>
>
> > NoName schrieb:

>
> > > On 25 ÄÅË, 00:37, "Diez B. Roggisch" <(E-Mail Removed)..de> wrote:
> > >> NoName schrieb:

>
> > >>> i have 1.py in cp866 encoding:
> > >>> # -*- coding: cp866 -*-
> > >>> print ("ff")
> > >>> It's not work in Python 3.0
> > >>> Error:
> > >>> File "<decoding error>", line 1
> > >>> SyntaxError: encoding problem: with BOM
> > >>> what's wrong?
> > >> I can only guess, but just because you write the coding-header that
> > >> doesn't mean that the editor you use does actually *use* that encoding.
> > >> What I presume it does is to use utf-8, and write that stupid BOM
> > >> microsoft uses for denoting utf-8-content as first byte. Try using a
> > >> different editor, or alter it's settings to really use your desired
> > >> encoding.

>
> > >> Diez

>
> > > I used Far Manager editor. and it *really* used cp866
> > > I can print hex dump of source file.
> > > I don't want to use UTF-8 for py-file!

>
> > How about you show us the python file in question?

>
> > diez

>
> you can get it here http://slil.ru/26481345


NoName, Asking people to download a zip file from a website written in
a language and character set that they probably are not familiar with
is liable to make them rather nervous and not bother. It's not a good
way to ask for help. All you had to do was display the file contents
unambiguously, like this:

C:\downloads>\python30\python
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open('11.py', 'rb').read()

b"# -*- coding: cp866 -*- \r\nprint('test')"
>>> ^Z


So, there's nothing very remarkable there ... a trailing space on the
end of the first line, the second line is not terminated by \r\n, no
non-ASCII characters in the file, ... nothing that might cause Python
to give you a syntax error.

.... and it doesn't give a syntax error:

C:\downloads>\python30\python 11.py
test

If you still maintain that you are getting the syntax error mentioned
in your first posting, please construct a file that causes the error
to happen on your machine (what type of machine? what OS are you
using?) and show (like I did above) firstly what is in the file and
secondly what happens when you run it. No hex editors, no websites, no
zip files, just plain Python like I did.
 
Reply With Quote
 
NoName
Guest
Posts: n/a
 
      12-25-2008
> NoName, Asking people to download a zip file from a website written in
> a language and character set that they probably are not familiar with
> is liable to make them rather nervous and not bother. It's not a good
> way to ask for help.


sorry

Now i know where problem.
But i dont know how to solve it.

Error
----
C:\Documents and Settings\Ra\ >11.py
File "<decoding error>", line 1
SyntaxError: encoding problem: with BOM

No error
----
C:\Documents and Settings\Ra\ >python 11.py
test

Error when russian symbols in full path to py-script.
Is it Python bug? or i need to modify some registry keys?

OS: WinXP SP3 Russian.
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32


 
Reply With Quote
 
NoName
Guest
Posts: n/a
 
      12-26-2008

> It's a bug, please report it. I though we fixed all Windows path bugs
> for 3.0 but apparently one slipped through.
>
> Christian


It is too difficult for me. please help me=)
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-26-2008
En Thu, 25 Dec 2008 11:55:16 -0200, NoName <(E-Mail Removed)> escribió:

> Error
> ----
> C:\Documents and Settings\Ra\*абочий стол>11.py
> File "<decoding error>", line 1
> SyntaxError: encoding problem: with BOM
>
> No error
> ----
> C:\Documents and Settings\Ra\*абочий стол>python 11.py
> test
>
> Error when russian symbols in full path to py-script.
> Is it Python bug? or i need to modify some registry keys?


Yes, it's a bug. The encoding declaration may be anything, ascii, even an
inexistent codec will trigger the bug. Any non-ascii character in the
script name or path provokes then a SyntaxError when the script is
executed directly.
As a workaround, avoid using any Russian characters in directory names or
script file names, or invoke them always using "python xxx.py", not
directly.

> OS: WinXP SP3 Russian.
> Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
> (Intel)] on win32


My tests were on WinXP SP3 Spanish.
See http://bugs.python.org/issue4747

--
Gabriel Genellina

 
Reply With Quote
 
NoName
Guest
Posts: n/a
 
      12-27-2008
On 26 է֧, 23:08, "Gabriel Genellina" <(E-Mail Removed)> wrote:
> En Thu, 25 Dec 2008 11:55:16 -0200, NoName <(E-Mail Removed)> escribi:
>
> > Error
> > ----
> > C:\Documents and Settings\Ra\ѧҧڧ >11.py
> > File "<decoding error>", line 1
> > SyntaxError: encoding problem: with BOM

>
> > No error
> > ----
> > C:\Documents and Settings\Ra\ѧҧڧ >python 11.py
> > test

>
> > Error when russian symbols in full path to py-script.
> > Is it Python bug? or i need to modify some registry keys?

>
> Yes, it's a bug. The encoding declaration may be anything, ascii, even an
> inexistent codec will trigger the bug. Any non-ascii character in the
> script name or path provokes then a SyntaxError when the script is
> executed directly.
> As a workaround, avoid using any Russian characters in directory names or
> script file names, or invoke them always using "python xxx.py", not
> directly.
>
> > OS: WinXP SP3 Russian.
> > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
> > (Intel)] on win32

>
> My tests were on WinXP SP3 Spanish.
> Seehttp://bugs.python.org/issue4747
>
> --
> Gabriel Genellina



Gabriel Genellina, thanks for bug report =)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sniffing encoding type by looking at file BOM header python@bdurham.com Python 2 03-25-2010 11:21 PM
UTF - SEEK_SET workaround for BOM encoding(utf-16/32) layer Bug sln@netherlands.com Perl Misc 2 08-13-2009 11:35 PM
UTF-8 encoding with BOM under Ruby 1.8.x (Windows) Wolfgang Nádasi-Donner Ruby 5 08-16-2007 08:00 AM
UTF-8 BOM w/ ISO-8859-1 encoding pseudo attribute Erik Wahlstrom XML 1 08-18-2004 08:37 PM
TextStreamReader with transparent unicode BOM Support X_AWemner_X Java 3 07-03-2003 09:38 PM



Advertisments