温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决

发布时间:2022-05-20 17:48:40 来源:亿速云 阅读:177 作者:iii 栏目:开发技术

这篇文章主要介绍“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>hostname
AnatoliyVik-ПК

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

Thanks to @Lafada for the guidance.

到此,关于“gethostbyaddr在Python3中引发UnicodeDecodeError怎么解决”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI