Error while running Django app

陌路散爱 提交于 2019-12-20 04:09:51

问题


When I run django project in pycharm or cmd, I get this error. What Should I do?

"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 Validating models...

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

回答1:


I have not tested it, but I suppose this is a python error. The stack trace you have provided suggests, that the UnicodeDecodeError gets triggerd when your hostname gets copied into a python unicode string.

Please check if the hostname of the machine you are working on contains unicode characters.

This seems to be the same issue as yours. In the post the python Issue9377 is referenced which is still open.




回答2:


1) Check your settings.py manage.py wsgi.py etc. for the non-ascii literals.

2) When found add

# -*- coding: utf-8 -*-

at the beginning of your files

3) And add u at the beggining of strings that contains non-ascii literals

eg: u"This characters are not unicode : üşiğç"

///for python 2.x




回答3:


Try to verify host name. Migth be your host name contains some non-ascii literals. Seems that you use Windows 7 OS.



来源:https://stackoverflow.com/questions/25324014/error-while-running-django-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!