Pycharm在Django服务器调试模式下返回非ASCII错误,在正常运行模式下可以正常工作。

3

我有一个Django服务器在本地运行了一段时间。今天突然在调试模式下出现错误,但在正常模式下可以正常工作。

我尝试在manage.py中包含utf-8,但仍然看到错误。

pydev debugger: process 10424 is connecting

Connected to pydev debugger (build 192.6603.34)
pydev debugger: process 10425 is connecting

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2066, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2060, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1411, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1418, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python", line 1
SyntaxError: Non-ASCII character '\xcf' in file /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details```


I expect it to run on debug mode. it already bloked me 1/2 day. Please help if you already have seen this issue or know how to fix this.

我尝试重新安装了PyCharm,但我不知道这个非ASCII字符在哪里。 - Raj
3个回答

5
('sys.argv', ['/Volumes/128GB/tests/testweb/manage.py', 'runserver', '7000'])

Connected to pydev debugger (build 192.6817.19)

pydev debugger: process 19300 is connecting

('setup', {'multiproc': True, 'save-asyncio': False, 'vm_type': None, 'save-threading': False, 'save-signatures': False, 'multiprocess': False, 'module': False, 'server': False, 'client': '127.0.0.1', 'file': '/Volumes/128GB/tests/testweb/manage.py', 'DEBUG_RECORD_SOCKET_READS': False, 'cmd-line': False, 'print-in-debugger-startup': False, 'qt-support': '', 'port': 52573})



('sys.argv', ['/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py', '--port', '52573', '--client', '127.0.0.1', '--multiproc', '--file', '/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '/Volumes/128GB/tests/testweb/manage.py', 'runserver', '7000'])

pydev debugger: process 19301 is connecting

('setup', {'multiproc': True, 'save-asyncio': False, 'vm_type': None, 'save-threading': False, 'save-signatures': False, 'multiprocess': False, 'module': False, 'server': False, 'client': '127.0.0.1', 'file': '/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', 'DEBUG_RECORD_SOCKET_READS': False, 'cmd-line': False, 'print-in-debugger-startup': False, 'qt-support': '', 'port': 52573})

  • 操作系统: macOS 10.15.1 (19B88)
  • Python版本: 2.7.16
  • PyCharm版本: 2019.2.3 (社区版)

我的问题也是如此。

pydev应该解析执行python脚本文件到“--file”参数。但当fork一个子进程时,它会将python二进制文件添加到“--file”参数中。
天哪,这浪费了我很多时间来处理。但根本原因仍未找到。

您可以在您的pydev_monkey.py文件中,在PyCharm安装目录下,以下面的代码:

from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv

下方添加:

args = args[1:]

这可以暂时使Debug功能正常运作。

例如,在我的电脑上,路径为/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey.py


1
尝试使用noreload运行,似乎在自动重新加载程序生成子进程时失败了,因为pydev尝试将python可执行文件解释为脚本。截图

0

使用noreload运行可以解决“SyntaxError: Non-ASCII character '\xcf' in file”问题。当我在正常模式下运行时,还有另一个问题。 输入图像描述 SyntaxError: Non-ASCII character '\xe6'

为了定义源代码编码,必须将魔术注释放置到源文件中,作为文件的第一或第二行(例如/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_monkey.py),如下所示: "# --coding:utf-8 -- "


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接