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.

Vika Herko
  • 13
  • 2
  • Possible duplicate of [UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c](https://stackoverflow.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c) – Michele Bastione Nov 05 '19 at 11:59
  • Have you read [UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 388: invalid continuation byte](https://stackoverflow.com/q/58421078/1016716), [UnicodeDecodeError: 'utf-8' codec can't decode byte](https://stackoverflow.com/q/19699367/1016716), [UnicodeDecodeError when reading CSV file in Pandas with Python](https://stackoverflow.com/q/18171739/1016716), [UnicodeDecodeError, invalid continuation byte](https://stackoverflow.com/q/5552555/1016716) etc. – Mr Lister Nov 05 '19 at 13:07

1 Answers1

0

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
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • This [issue](https://bugs.python.org/issue26227) was supposedly fixed in Python 3.5, so it would be interesting to know what is in your hosts file. – snakecharmerb Nov 05 '19 at 18:59
  • 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? – Vika Herko Nov 06 '19 at 00:10
  • 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. – snakecharmerb Nov 06 '19 at 06:49
  • 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. – Raul Luna Jan 12 '21 at 07:07