报错

* Debugger is active!
* Debugger PIN: 575-216-393
Exception in thread Thread-1:
Traceback (most recent call last):
File "G:\Projects\python-3.6.4-amd64\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "G:\Projects\python-3.6.4-amd64\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "G:\Projects\pycharmeProject-C21\projects\Test02\venv\lib\site-packages\werkzeug\serving.py", line 959, in inner
fd=fd,
File "G:\Projects\pycharmeProject-C21\projects\Test02\venv\lib\site-packages\werkzeug\serving.py", line 783, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File "G:\Projects\pycharmeProject-C21\projects\Test02\venv\lib\site-packages\werkzeug\serving.py", line 688, in __init__
super().__init__(server_address, handler) # type: ignore
File "G:\Projects\python-3.6.4-amd64\lib\socketserver.py", line 453, in __init__
self.server_bind()
File "G:\Projects\python-3.6.4-amd64\lib\http\server.py", line 138, in server_bind
self.server_name = socket.getfqdn(host)
File "G:\Projects\python-3.6.4-amd64\lib\socket.py", line 673, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 4: invalid start byte

分析

最近在使用python处理数据,原本写的好好的程序都可以运行,中间一天没用,今天打开一看莫名其妙报了个类似字符编码的问题。我尝试更换环境进行运行,可还是报同样的错误,很不理解😖😖😖


解决方案

flask框架run这个方法的作用是获取当前计算机的名字因为windows环境电脑名字是中文,所以报这个错误,改成英文重启电脑就可以。说实话看到这个说明的时候有点蒙,但又不是不可以接受,毕竟是和本机名有关hostname, aliases, ipaddrs = gethostbyaddr(name),我的电脑名称确实是中文😎😎😎,没办法,试试:

  • 计算机 - ​属性​ - ​重命名这台电脑​ -> ​计算机名​
  • 【Python】UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xba in position 4: invalid start byte_python


  • 【Python】UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xba in position 4: invalid start byte_重命名_02

  • 重命名后重启一下~
  • 再次尝试运行程序即可!!!