当我在pycharm或cmd中运行django项目时,我收到此错误。我该怎么办?
“C:\ Program Files(x86)\ JetBrains \ PyCharm 3.4.1 \ bin \ runnerw.exe”C:\ Python34 \ python.exe C:/Users/admin/PycharmProjects/untitled/manage.py runserver 8000 验证模型......
0 errors found
August 15, 2014 - 13:58:27
Django version 1.6.5, using settings 'untitled.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 0x022A32B8>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 127, in inner_run
ipv6=self.use_ipv6, threading=threading)
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 167, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 109, in __init__
super(WSGIServer, self).__init__(*args, **kwargs)
File "C:\Python34\lib\socketserver.py", line 429, in __init__
self.server_bind()
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 113, in server_bind
super(WSGIServer, self).server_bind()
File "C:\Python34\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "C:\Python34\lib\http\server.py", line 135, in server_bind
self.server_name = socket.getfqdn(host)
File "C:\Python34\lib\socket.py", line 460, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 6: invalid continuation byte
答案 0 :(得分:0)
1)检查 settings.py manage.py wsgi.py 等非ascii文字。
2)找到后添加
# -*- coding: utf-8 -*-
在文件的开头
3)并在包含非ascii文字
的字符串的开头添加u例如:你“这个字符不是unicode:üşiğç”
/// for python 2.x
答案 1 :(得分:0)
我还没有测试过它,但我认为这是一个python错误。您提供的堆栈跟踪表明,当您的主机名被复制到python unicode字符串时会触发UnicodeDecodeError。
请检查您正在使用的计算机的主机名是否包含unicode字符。
答案 2 :(得分:0)
尝试验证主机名。 Migth是你的主机名包含一些非ascii文字。 似乎您使用的是Windows 7操作系统。