I create a new project on Django using PyCharm. I do not change anything. When starting a project, the error is knocked out:

"C:\Program Files (x86)\JetBrains\PyCharm 5.0.3\bin\runnerw.exe" C:\Python34\python.exe E:/Projects/Proj_test/manage.py runserver 8000 Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. January 23, 2016 - 12:55:37 Django version 1.9.1, using settings 'Proj_test.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 0x036E9078> Traceback (most recent call last): [...] File "C:\Python34\lib\http\server.py", line 138, in server_bind self.server_name = socket.getfqdn(host) File "C:\Python34\lib\socket.py", line 467, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 0: invalid continuation byte 

The situation is similar when using Visual Studio. Changing the version of Python does not solve. I use Windows 7.

Tell me how you can solve this error.

5 answers 5

This was a bug in Python 3.4: Windows: socket.gethostbyaddr (name) fails for non-ASCII hostname . It is fixed, so upgrading to Python version 3.5+ should help.

If you cannot upgrade, try passing the host name as an ip address (for example, python manage.py runserver 127.0.0.1:8000 ) or rename the host so that the name does not have non-ASCII characters.

  • I agree with you, here the problem is still in early versions of python3, they generally have a lot of problems with the encoding. In this case, in the socket module. I recommend updating python, for example, updating version 3.5.1 to 3.5.3 solves this problem for python 3.5 - leexxg
  • Hmm, and here is a similar error already in Python 3.6 - andreymal
  • And here already in Python 3.7, strange - andmal

In the above error output you can see:

You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them.

and also:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 0: invalid continuation byte

Most likely problems with the coding.

Apparently in the file is the Russian letter B (in the cp1251 encoding, typical for Windows), but somewhere in the depths of the project it is indicated that the encoding is expected to be utf-8 ...

  • 2
    UTF8 encoding is specified in Python itself. It was a bug - jfs

The issue is resolved. The problem was that the computer name was indicated by the Cyrillic. Changed to Latin and everything is ok.

    I had the same Windows 8 problem. Changing the user name in Latin did not help. In debug I discovered that the path with the Cyrillic character C: \ Users \ User is supplied to the utf-8.py file. In the input variable substituted path. And it all worked.

     def decode(input, errors='strict'): try: codecs.utf_8_decode(input, errors, True) except: input='c://windows' pass return codecs.utf_8_decode( input, errors, True) 

      Something difficult answers. Why all this when you can just open the desired page in Notepad ++ and convert it to utf-8 because the debugger described that the essence of his problem is only that he met a character in some kind of framing which is not quite similar to unicode