M
M
Moroz228482019-08-31 02:29:12
Django
Moroz22848, 2019-08-31 02:29:12

Why won't the Django server start?

My Django server does not start. In the console, I did everything as in the Django video tutorials, created the project folder through the console (django-admin startproject myfirst), then went to the myfirst folder where the manage.py file was located, entered "python manage. py runserver" and gave an error:
D:\MySiite\myfirst>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you
apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 31, 2019 - 02:20:26
Django version 2.2.4, using settings 'myfirst.
Starting development server at 127.0.0.1:8000
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "D:\Python 3\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "D:\Python 3\ lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\Python 3\lib\site-packages\django\utils\autoreload.py", line 54, in w
rapper
fn(*args, **kwargs)
File "D:\Python 3\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:\Python 3\lib\site-packages\django\core\servers\basehttp.py", line 203
, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "D:\Python 3\ lib\site-packages\django\core\servers\basehttp.py", line 67,
in __init__
super().__init__(*args, **kwargs)
File "D:\Python 3\lib\socketserver.py", line 452, in __init__
self.server_bind()
File "D:\Python 3\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "D:\Python 3\lib\http\ server.py", line 139, in server_bind
self.server_name = socket.getfqdn(host)
File "D:\Python 3\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 0: invalid
start byte
PS: Launched via console (OS Windows 7)
There is no Cyrillic in the project path (D: \MySite\myfirst)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-08-31
@Moroz22848

Already answered , I'll quote the answer:
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
я попробовал воспроизвести подобную ошибку в среде Win 10 (в VirtualBox) и у меня получилось только в случае
если в файле hosts присутствует алиас с кириллицей и локаль Windows русская.
Если удалить русский, оставив только английский (на русском только интерфейс системы), то всё ок.
Так-же не удалось воспроизвести ошибку если при запуске указывать ip хоста как 127.0.0.2
При условии, что в hosts нет алиаса с кириллицей для него.
На чистой системе (установлены только Python 3.7.2 и Pycharm Community, русская локаль) подобной ошибки нет.
Заглянул в исходники socket.py и socketmodule.c
Скорее всего данная особенность связаны с этой частью исходного кода Python на C, а именно 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

Далее, если имя хоста не написано кириллицей и в hosts нет кириллицы следует вывод, что с высокой долей вероятности дело в стороннем софте(антивирус, кривой кряк и т.д.).
So:
  • Update Python
  • Rename host
  • Remove alias(s) in hosts file
  • Check third-party software (antivirus, crooked crack, etc.)
  • Or run Django by passing it an ip address instead of a hostname: python manage.py runserver 127.0.0.1:8000
  • Run like this: python manage.py runserver 127.0.0.2:8000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question