Skip to main content
 首页 » 编程设计

python之gethostbyaddr() 在 Python 3 中引发 UnicodeDecodeError

2025年05月04日9luoye11

<分区>

我正在尝试使用 Python 3.4.1 构建一个 Django 项目。 manage.py runserver 引发 UnicodeDecodeException。

如何解决?请参阅下面的(修剪过的)回溯:

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 

根据请求,我的主机名:

C:\Users\AnatoliyVik>hostname 
AnatoliyVik-ПК