启动使用该工具创建的全新django项目时的UnicodeDecodeError

时间:2014-09-01 17:23:31

标签: python django windows encoding django-admin

更新:我从python 3.4降级到3.3.5,所以Django与它兼容,但问题仍然存在:

我对python和django非常了解,我在Windows笔记本电脑中安装了python 3.3.5 和Django 1.6.6。我正在关注django教程,但我陷入了第二步,因为我收到了一个错误。

我创建了项目:

django-admin startproject TouristGuide

然后我进入了创建的文件夹,其中包含manage.py所在的旅游指南

cd TouristGuide

然后我按照教程的建议启动服务器:

python manage.py runserver

当我执行该行时,我收到以下错误:

Validating models...

0 errors found
September 01, 2014 - 23:11:07
Django version 1.6.6, using settings 'TouristGuide.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
 at 0x02B4E9C0>
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\django\utils\autoreload.py", line 93, in w
rapper
    fn(*args, **kwargs)
  File "C:\Python33\lib\site-packages\django\core\management\commands\runserver.
py", line 128, in inner_run
    ipv6=self.use_ipv6, threading=threading)
  File "C:\Python33\lib\site-packages\django\core\servers\basehttp.py", line 167
, in run
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
  File "C:\Python33\lib\site-packages\django\core\servers\basehttp.py", line 109
, in __init__
    super(WSGIServer, self).__init__(*args, **kwargs)
  File "C:\Python33\lib\socketserver.py", line 430, in __init__
    self.server_bind()
  File "C:\Python33\lib\site-packages\django\core\servers\basehttp.py", line 113
, in server_bind
    super(WSGIServer, self).server_bind()
  File "C:\Python33\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "C:\Python33\lib\http\server.py", line 137, in server_bind
    self.server_name = socket.getfqdn(host)
  File "C:\Python33\lib\socket.py", line 386, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 4: invalid
continuation byte

2 个答案:

答案 0 :(得分:0)

我希望我能把它放在评论中,但我还没有足够的声誉。根据该文档,Django 1.6不支持Python 3.4。有关详细信息,请阅读FAQ。您需要将Python降级到3.3或将Django升级到1.7。

答案 1 :(得分:0)

问题是我的笔记本电脑的名称是“Portátil”,当python使用gethostbyaddr时,它的响应具有该名称,而且似乎python无法正确处理编码。我已经更改了笔记本电脑的名称,所以现在它不包含任何重音字符。