You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SyntaxError executing a script containing non-ASCII characters in its name or path #48997
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2009-01-01.23:07:48.457>created_at=<Date2008-12-26.00:41:46.474>labels= ['interpreter-core', 'build', 'OS-windows']
title='SyntaxError executing a script containing non-ASCII characters in its name or path'updated_at=<Date2009-01-01.23:07:48.456>user='https://bugs.python.org/ggenellina'
Attempting to directly execute a script containing non-ASCII
characters in its name or path raises SyntaxError.
The script contents are mostly irrelevant, except it must contain an
encoding declaration (with *any* encoding, real or inexistent).
Running "python foo.py" works, but invoking it directly as "foo.py"
raises SyntaxError: None, or sometimes SyntaxError: encoding problem: with BOM (no BOM is present in the source file, a plain
ASCII text file).
C:\TEMP>cd áéíóú
C:\TEMP\áéíóú>type test.py
# -- coding: ascii --
C:\TEMP\áéíóú>C:\Apps\Python30\python.exe test.py
C:\TEMP\áéíóú>test.py
SyntaxError: None
To avoid any doubt, the file has no strange characters:
Activity
ggenellina commentedon Dec 26, 2008
Attempting to directly execute a script containing non-ASCII
characters in its name or path raises SyntaxError.
The script contents are mostly irrelevant, except it must contain an
encoding declaration (with *any* encoding, real or inexistent).
Running "python foo.py" works, but invoking it directly as "foo.py"
raises
SyntaxError: None, or sometimesSyntaxError: encoding problem: with BOM(no BOM is present in the source file, a plainASCII text file).
C:\TEMP>cd áéíóú
C:\TEMP\áéíóú>type test.py
# -- coding: ascii --
C:\TEMP\áéíóú>C:\Apps\Python30\python.exe test.py
C:\TEMP\áéíóú>test.py
SyntaxError: None
To avoid any doubt, the file has no strange characters:
C:\TEMP\áéíóú>python -c "print(repr(open('test.py','rb').read()))"
'# -- coding: ascii --\r\n'
and .py files are associated with the same interpreter:
C:\TEMP\áéíóú>assoc .py
.py=Python.File
C:\TEMP\áéíóú>ftype Python.File
Python.File="C:\Apps\Python30\python.exe" "%1" %*
The same thing happens if the file name contains any non-ASCII
character (the path may be pure ASCII).
amauryfa commentedon Dec 31, 2008
This also happens if there is any kind of syntax error in the file:
"SyntaxError: None" is printed without any other hint.
The (char*) filename passed to PyRun_AnyFile should be utf-8 encoded;
Otherwise the file cannot be re-opened.
Attached patch fixes both issues, please review.
It removes one occurrence of wcstombs in favor of the PyUnicode machinery.
vstinner commentedon Dec 31, 2008
I'm unable to reproduce the problem on Linux. I wrote a
script /home/haypo/ééé/ééé.py:
---------------
The script runs fine:
$ ./ééé.py
a
$ /home/haypo/prog/SVN/py3k/python ééé.py
a
Is the problem specific to Windows?
amauryfa commentedon Dec 31, 2008
Yes. As usual, the problem occurs when the platform encoding (used by
wcstombs) is not utf-8.
benjaminp commentedon Dec 31, 2008
Looks good.
amauryfa commentedon Jan 1, 2009
Fixed in r68143 (py3k) and r68144 (3.0).
Thanks for the report!