Error starting the Django server. What to do?

Falls error when you run the Django server. Like writes that an error in the encoding, but I don't 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
March 23rd 20 at 19:23
2 answers
March 23rd 20 at 19:25
Solution
The host name written in Cyrillic and Python 3.4 or older?
Windows: socket.gethostbyaddr(name) fails for non-ASCII hostname
bugs.python.org/issue26227

  • Update Python
  • To rename the host
  • Or you can run Django passing it the ip address instead of the hostname python manage.py runserver 127.0.0.1:8000
UPD:

I tried to reproduce this error in Win 10 environment (in VirtualBox) and I did it just in case
if the hosts file there is an alias with the Cyrillic alphabet and the Windows locale is Russian.
spoiler
5cfb3a55d8bd0793644215.png5cfb39ec9a939231168766.png

If you delete the Russian one, leaving only English (in Russian only system interface), then everything is OK.

So the same could not reproduce the error if you run the specify the host ip as 127.0.0.2
python manage.py runserver 127.0.0.2:8080
Provided that in hosts no alias with the Cyrillic alphabet for it.

On a clean system (just installed Python and Pycharm Community 3.7.2, Russian locale), these errors are not.

Looked in the source code socket.py and socketmodule.c
Most likely, this feature connected with this part of the source code of Python in C, namely PyUnicode_DecodeFSDefault
#ifdef MS_WINDOWS
 /* Issue #26227: gethostbyaddr() returns a string encoded
 * to the ANSI code page */
 PyUnicode_DecodeFSDefault return(name);
#else
 /* Decode from UTF-8 */
 return PyUnicode_FromString(name);
#endif


Further, if the host name is not written in Cyrillic and hosts no Cyrillic it can be concluded that with high probability the case in third-party software(antivirus, curve crack, etc.).
Did not help) - johathan.Crooks54 commented on March 23rd 20 at 19:28
@johathan.Crooks54, OK
Then come the steps:
  • The Version Of Python
  • Version Of Django
  • The hostname
  • How to start Django
  • Do you use a venv
- brandyn_Schimmel commented on March 23rd 20 at 19:31
Python 3.7.3
Django 2.2.2
Host name - localhost
Run a python command manage.py runserver
Using a virtual environment (venv) - johathan.Crooks54 commented on March 23rd 20 at 19:34
@johathan.Crooks54well
What version of the OS (in full)? - brandyn_Schimmel commented on March 23rd 20 at 19:37
@johathan.Crooks54, So I tried to run:
python manage.py runserver 0.0.0.0:8000
and
python manage.py runserver 127.0.0.1:8000
? - brandyn_Schimmel commented on March 23rd 20 at 19:40
@brandyn_Schimmel, tried. But you can try again - johathan.Crooks54 commented on March 23rd 20 at 19:43
@brandyn_Schimmel, win 10 insider preview - johathan.Crooks54 commented on March 23rd 20 at 19:46
@brandyn_Schimmel, no, these command are not working - johathan.Crooks54 commented on March 23rd 20 at 19:49
@johathan.Crooks54, I seem to be getting closer.
You need the contents of the file hosts from the directory C:\Windows\System32\drivers\etc
Most likely you or some software made changes to the file. - brandyn_Schimmel commented on March 23rd 20 at 19:52
@brandyn_Schimmel,
For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
Here - johathan.Crooks54 commented on March 23rd 20 at 19:55
Difficult! It is not clear and the error is not left... - johathan.Crooks54 commented on March 23rd 20 at 19:58
March 23rd 20 at 19:27
You have the last line written...
You gave where the string format is not the UTF....
Find this line and add encode()
encode()
Otherwise, it is impossible?) - johathan.Crooks54 commented on March 23rd 20 at 19:30
@johathan.Crooks54, Well, if it worked, it is obvious that the framework uses it ЮТФ8 and even suggests that you want him another to feed...
We can of course change the framework(from task dependent), for example on the tornado(it is...) or flask(small enough). - joana.Marquardt1 commented on March 23rd 20 at 19:33
@joana.Marquardt1,
from django.db import models

str = u 'date of publication'

class Post(models.Model):
 title = models.CharField(max_length=255) # the title of the post

 datetime = models.DateTimeField(str .encode ('utf-8', 'strict')) # date of publication
 content = models.TextField(max_length=10000) # the text of the post

 def __unicode__(self):
 return self.title

 def get_absolute_url(self):
 return "/blog/%i/" % self.id

Not working. It models.py
I need a blog on Python - johathan.Crooks54 commented on March 23rd 20 at 19:36
Error 676-th line of the file c:\python37-32\Lib\socket.py I Think that the code in this file is the author writing? - anais_Ortiz85 commented on March 23rd 20 at 19:39
@anais_Ortiz85, Yes, You are right. In the files that were in Django I didn't touch at all. - johathan.Crooks54 commented on March 23rd 20 at 19:42

Find more questions by tags Django