Skip to content

SyntaxError executing a script containing non-ASCII characters in its name or path #48997

Closed

Description

@ggenellina
BPO 4747
Nosy @amauryfa, @vstinner, @benjaminp
Files
  • unicode_scriptname.patch
  • 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 = None
    closed_at = <Date 2009-01-01.23:07:48.457>
    created_at = <Date 2008-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 = <Date 2009-01-01.23:07:48.456>
    user = 'https://bugs.python.org/ggenellina'

    bugs.python.org fields:

    activity = <Date 2009-01-01.23:07:48.456>
    actor = 'amaury.forgeotdarc'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-01.23:07:48.457>
    closer = 'amaury.forgeotdarc'
    components = ['Interpreter Core', 'Windows']
    creation = <Date 2008-12-26.00:41:46.474>
    creator = 'ggenellina'
    dependencies = []
    files = ['12506']
    hgrepos = []
    issue_num = 4747
    keywords = ['patch']
    message_count = 6.0
    messages = ['78286', '78614', '78617', '78621', '78650', '78737']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'ggenellina', 'vstinner', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue4747'
    versions = ['Python 3.0']

    Activity

    1. ggenellina commented on Dec 26, 2008

      ggenellinamannequin
      MannequinAuthor

      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:

      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).

    2. amauryfa commented on Dec 31, 2008

      @amauryfa
      Contributor

      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.

    3. vstinner commented on Dec 31, 2008

      @vstinner
      Member

      I'm unable to reproduce the problem on Linux. I wrote a
      script /home/haypo/ééé/ééé.py:
      ---------------

      #!/home/haypo/prog/SVN/py3k/python
      # -*- coding: ascii -*-
      print("a")

      The script runs fine:
      $ ./ééé.py
      a
      $ /home/haypo/prog/SVN/py3k/python ééé.py
      a

      Is the problem specific to Windows?

    4. amauryfa commented on Dec 31, 2008

      @amauryfa
      Contributor

      Yes. As usual, the problem occurs when the platform encoding (used by
      wcstombs) is not utf-8.

    5. benjaminp commented on Dec 31, 2008

      @benjaminp
      Contributor

      Looks good.

    6. amauryfa commented on Jan 1, 2009

      @amauryfa
      Contributor

      Fixed in r68143 (py3k) and r68144 (3.0).
      Thanks for the report!

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      OS-windowsbuildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions