Python之Dijango的“坑” hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' cod

来源:互联网 发布:淘宝网连衣裙夏装 编辑:程序博客网 时间:2024/04/29 12:52


           在命令行输入 python manage.py runserver启动服务器的时候,突然出现下面的错误

     

Traceback (most recent call last):  File "learning.py", line 106, in <module>    main()  File "learning.py", line 37, in main    httpd = make_server('127.0.0.1', PORT, application)  File "D:\Program Files\Python34\lib\wsgiref\simple_server.py", line 153, in make_server    server = server_class((host, port), handler_class)  File "D:\Program Files\Python34\lib\socketserver.py", line 430, in __init__    self.server_bind()  File "D:\Program Files\Python34\lib\wsgiref\simple_server.py", line 50, in server_bind    HTTPServer.server_bind(self)  File "D:\Program Files\Python34\lib\http\server.py", line 135, in server_bind    self.server_name = socket.getfqdn(host)  File "D:\Program Files\Python34\lib\socket.py", line 463, in getfqdn    hostname, aliases, ipaddrs = gethostbyaddr(name)UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 0: invalidcontinuation byte

     分析  :重点是最后一句红色的话,从中我们可以看出,是要得要你自己电脑的主机名,但是现在的主机名是中文,所以导致编码出现错误

    解决方案:把你自己电脑的主机名改成英文的,不要写中文,然后重启电脑就可以了

    :你可以在python中的socket.py 中来看一下出错的地方

            

if not name or name == '0.0.0.0':    name = gethostname()try:    hostname, aliases, ipaddrs = gethostbyaddr(name)except error:    passelse:


0 0
原创粉丝点击