M
M
Michael La2019-06-06 17:35:57
Django
Michael La, 2019-06-06 17:35:57

Error starting Django server. What to do?

An error occurs when starting the Django server. It seems to write that the error is in the encoding, but I do not know how to fix it.

System check identified no issues (0 silenced).
June 06, 2019 - 17:33:13
Django version 2.2.2, using settings 'blogglav.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "c:\python37-32\Lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "c:\python37-32\Lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "D:\CODE\py-ru\Django\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "D:\CODE\py-ru\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 139, in inner_run
    ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
  File "D:\CODE\py-ru\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 203, in run
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
  File "D:\CODE\py-ru\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 67, in __init__
    super().__init__(*args, **kwargs)
  File "c:\python37-32\Lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "c:\python37-32\Lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "c:\python37-32\Lib\http\server.py", line 139, in server_bind
    self.server_name = socket.getfqdn(host)
  File "c:\python37-32\Lib\socket.py", line 676, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 5: invalid continuation byte

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2019-06-06
@Mihail_Tropin

Is the hostname written in Cyrillic and Python 3.4 or older?
Windows: socket.gethostbyaddr(name) fails for non-ASCII hostname
bugs.python.org/issue26227
I tried to reproduce a similar error in the Win 10 environment (in VirtualBox) and I succeeded only
if the hosts file contains an alias with Cyrillic and the Windows locale is Russian.
If you remove Russian, leaving only English (in Russian, only the system interface), then everything is ok.
It also failed to reproduce the error if you specify the host ip as 127.0.0.2
at startup , provided that hosts does not have an alias with Cyrillic for it.
On a clean system (only Python 3.7.2 and Pycharm Community installed, Russian locale) there is no such error.
Looked into the sources of socket.py and socketmodule.c
Most likely this feature is related to this part of the Python source code in C, namely PyUnicode_DecodeFSDefault

#ifdef MS_WINDOWS
    /* Issue #26227: gethostbyaddr() returns a string encoded
     * to the ANSI code page */
    return PyUnicode_DecodeFSDefault(name);
#else
    /* Decode from UTF-8 */
    return PyUnicode_FromString(name);
#endif

Further, if the host name is not written in Cyrillic and there is no Cyrillic alphabet in hosts, the conclusion follows that with a high degree of probability the matter is in third-party software (antivirus, crooked crack, etc.).

P
Proritsatel, 2021-01-13
@Proritsatel

I solved the problem by removing the prefix in the computer name, although in cmd the name was displayed only in Latin letters, -PC was appended to it, this was the problem.
Change the computer name through My computer - Properties - Advanced settings System - Computer name - Change

J
justAnotherCluelessUser, 2019-06-06
@justAnotherCluelessUser

In your last line, it says...
You passed a string somewhere in a non-YTF format....
Find this line and add encode()
encode()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question