Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that gethostbyaddr triggers UnicodeDecodeError in Python3

Shulou Source: shulou.com Published: 2022-05-31 16:25:55 10月29日 Update

This article mainly introduces "how to solve UnicodeDecodeError caused by gethostbyaddr in Python3". In daily operation, I believe that many people have doubts about how to solve problems caused by UnicodeDecodeError in gethostbyaddr in Python3. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt that "gethostbyaddr causes UnicodeDecodeError in Python3". Next, please follow the editor to study!

Problem description

I am using Python 3.4.1 to build a Django project.

Manage.py runserver throws UnicodeDecodeException.

How to solve?

View the following (trim) retro:

Retro (last recent call):

File C:\ Python34\ lib\ socketserver.py, line 429 _ _ init__ self.server_bind ()

File C:\ Python34\ lib\ site-packages\ django\ core\ servers\ basehttp.py, line 121, in server_bind Super (WSGIServer,self) .server_bind ()

File C:\ Python34\ lib\ wsgiref\ simple_server.py, line 50, server_bind HTTPServer.server_bind (self)

File C:\ Python34\ lib\ http\ server.py, line 135, server_bind self.server_name = socket.getfqdn (host)

File C:\ Python34\ lib\ socket.py, line 460, getfqdn hostname, alias, ipaddrs = gethostbyaddr (name)

UnicodeDecodeError:'utf-8' codec cannot decode 0xcf bytes in position 12 invalid contiguous bytes

For each request, my hostname:

C:\ Users\ AnatoliyVik > hostname AnatoliyVik- hosting solution

Change the hostname to no longer contain Cyrillic characters to resolve the problem.

Thank you @ Lafada for your guidance.

I'm trying to build a Django project with Python 3.4.1. Manage.py runserver raises a UnicodeDecodeException.

How can this be resolved? See the below (trimmed) traceback:

Traceback (most recent call last): File "C:\ Python34\ lib\ socketserver.py", line 429, in _ _ init__ self.server_bind () File "C:\ Python34\ lib\ site-packages\ django\ core\ servers\ basehttp.py", line 121, in server_bind super (WSGIServer, self). Server_bind () File "C:\ Python34\ lib\ wsgiref\ simple_server.py", line 50 In server_bind HTTPServer.server_bind (self) File "C:\ Python34\ lib\ http\ server.py", line 135, in server_bind self.server_name = socket.getfqdn (host) File "C:\ Python34\ lib\ socket.py", line 460, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr (name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 12: invalid continuation byte

Per request, my hostname:

C:\ Users\ AnatoliyVik > hostnameAnatoliyVik- stories

Changing the hostname to no longer include Cyrillic symbols resolves the problem.

Thanks to @ Lafada for the guidance.

At this point, the study of "how to solve the problem caused by gethostbyaddr in Python3" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: File host learning problem byte more help practical next location alias character article scheme method being theory knowledge article website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info OPPO Reno Docker NVidia