无法运行Django开发服务器(UnicodeDecodeError)

时间:2023-01-04 20:53:39

When I am trying to run django development server (using command line or pycharm Run feature) I get following error traceback:

当我尝试运行django开发服务器(使用命令行或pycharm运行功能)时,我得到以下错误回溯:

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x037EF170>
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 107, in inner_run
    self.check_migrations()
  File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 159, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 48, in __init__
    self.build_graph()
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 173, in build_graph
    self.load_disk()
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 95, in load_disk
    if name.endswith(".py"):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb9 in position 27: ordinal not in range(128)

How can I fix that?

我该如何解决这个问题?

Edit: I've checked how it works when I delete all migrations and re-create them. When I do so, server is starting without any issue. HOWEVER, when I've switched to another machine and tried to start server (I am syncing files via dropbox) error message appears again.

编辑:当我删除所有迁移并重新创建它们时,我已经检查了它是如何工作的。当我这样做时,服务器启动没有任何问题。但是,当我切换到另一台机器并尝试启动服务器(我通过Dropbox同步文件)时,会再次出现错误消息。

1 个解决方案

#1


1  

I met the similar problem when I ran python managy.py runserver with Django 1.10.

当我用Django 1.10运行python managy.py runserver时遇到了类似的问题。

My system is: win10.
Python version: 2.7.13 (in Anacoda)

我的系统是:win10。 Python版本:2.7.13(在Anacoda中)

The error traceback is below: enter image description here

错误回溯如下:在此处输入图像描述

I got the answer from Django project troubleshooting

我从Django项目故障排除中得到了答案

Your system locale may be a default ASCII locale, like the “C” locale on UNIX-like systems (can be checked by the locale command). If it’s the case, please refer to your system documentation to learn how you can change this to a UTF-8 locale.

您的系统区域设置可能是默认的ASCII区域设置,如类UNIX系统上的“C”区域设置(可以通过locale命令检查)。如果是这种情况,请参阅系统文档以了解如何将其更改为UTF-8语言环境。

So in Windows 10 I changed system locale from Chinese to English refer to this question --- How to change system locale in Windows 10 - The Language for - Microsoft Community.

所以在Windows 10中我将系统区域设置从中文更改为英文参考这个问题---如何在Windows 10中更改系统区域设置 - 用于 - Microsoft社区的语言。

Then I rebooted my computer, and it's OK to run python managy.py runserver again.

然后我重新启动了我的电脑,再次运行python managy.py runserver就可以了。

May it will help someone.

愿它能帮助别人。

#1


1  

I met the similar problem when I ran python managy.py runserver with Django 1.10.

当我用Django 1.10运行python managy.py runserver时遇到了类似的问题。

My system is: win10.
Python version: 2.7.13 (in Anacoda)

我的系统是:win10。 Python版本:2.7.13(在Anacoda中)

The error traceback is below: enter image description here

错误回溯如下:在此处输入图像描述

I got the answer from Django project troubleshooting

我从Django项目故障排除中得到了答案

Your system locale may be a default ASCII locale, like the “C” locale on UNIX-like systems (can be checked by the locale command). If it’s the case, please refer to your system documentation to learn how you can change this to a UTF-8 locale.

您的系统区域设置可能是默认的ASCII区域设置,如类UNIX系统上的“C”区域设置(可以通过locale命令检查)。如果是这种情况,请参阅系统文档以了解如何将其更改为UTF-8语言环境。

So in Windows 10 I changed system locale from Chinese to English refer to this question --- How to change system locale in Windows 10 - The Language for - Microsoft Community.

所以在Windows 10中我将系统区域设置从中文更改为英文参考这个问题---如何在Windows 10中更改系统区域设置 - 用于 - Microsoft社区的语言。

Then I rebooted my computer, and it's OK to run python managy.py runserver again.

然后我重新启动了我的电脑,再次运行python managy.py runserver就可以了。

May it will help someone.

愿它能帮助别人。