这篇文章主要介绍“gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决”,在日常操作中,相信很多人在gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
问题描述
我正在用Python 3.4.1来构建一个Django项目。
manage.py runserver 引发UnicodeDecodeException。
如何解决?
查看以下(修剪)追溯:
追溯(最近的最后一次呼叫):
文件C:\ Python34\lib\socketserver.py,第429行__init__ self.server_bind()
文件C:\Python34\lib\site-packages\django\core \servers\basehttp.py,第121行,在server_bind 超级(WSGIServer,self).server_bind()
文件C:\Python34\lib\wsgiref \simple_server.py,第50行,server_bind HTTPServer.server_bind(self)
文件C:\Python34\lib\http\server.py,第135行, server_bind self.server_name = socket.getfqdn(host)
文件C:\Python34\lib\socket.py,第460行,getfqdn 主机名,别名,ipaddrs = gethostbyaddr(name)
UnicodeDecodeError:'utf-8'编解码器无法解码位置12中的0xcf字节无效连续字节
每个请求,我的主机名:
C:\Users\AnatoliyVik>主机名 AnatoliyVik-ПК
解决方案
将主机名更改为不再包含西里尔字符解决问题。
感谢@拉法达的指导。
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-ПК
Changing the hostname to no longer include Cyrillic symbols resolves the problem.
Thanks to @Lafada for the guidance.
到此,关于“gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!