0

I am trying to run a newly created environment on a server and get UnicodeDecodeError.

Windows 7, 64-bit. I have created a virtual environment and directed code to the source folder. Here are django, python and virtualenv versions installed. I have tried installing older versions of django and python and got the same error.

When searching for troubleshooting recommendations I only find articles related to .csv and pandas.

Django==2.2.7
pytz==2019.3
virtualenv==16.7.7
PS: C:\Users\User\Dev\Selectia\src> python manage.py runserver

Here is the output:

Watching for file changes with StartReloader
Performing system checks...

System checkidentified no issues (0 silenced).
November 05, 2019 - 12:02:31
Django version 2.2.7, using setings 'foodie.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREALK.
Exception in thread django-main-thread:
Traceback (most recent call last):
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
   self.run()
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
  self._target(*self.args, **self._kwargs)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 54 in wrapper 
  fn(*args, **kwargs)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line 203, in run
  httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line 67, in __init__
  super().__init__(*args, **kwargs)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\socketserver.py", line 452, in __init__
  self.server_bind()
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\wsgiref\simple_server.py", line 50, in server_bind
  HTTPServer.server_bind(self)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\http\server.py", line 139, in server_bind
  self.server_name = socket.getfqdn(host)
 File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\socket.py", line 676, in getfqdn
  hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecoderError: 'utf-8' code can't decode byte 0xcf in position 5: invalid continuation byte

Could you please help me out to find out the ways how to address this error message?

P.S. This is my first web framework project and I have some knowledge in python. I would really appreciate any help provided. I would like to build my own website.

1

1 Answer 1

1

You have aliases in your hosts file which contain characters which cannot be decoded as UTF-8. Remove them to solve the problem (it's probably easiest to make any aliases ASCII-only).

The default location for the hosts file on Windows 7 is

 C:\Windows\System32\Drivers\etc\hosts
Sign up to request clarification or add additional context in comments.

4 Comments

This issue was supposedly fixed in Python 3.5, so it would be interesting to know what is in your hosts file.
I have gone to noted above folder and checked all the files from UTF-8 validator. All files were validated well. Is there a way I could share files from hosts folder with you?
If the hosts file isn't very big (and does not contain any sensitive information) you could paste the contents into your question. The output of open(r'C:\Windows\System32\Drivers\etc\hosts', 'rb').read() would be particularly useful, as it would show the actual bytes.
I've got the very same error, and my hosts file is completely normal. It has the default contents and three lines, that are ascii - 127.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.