python创建服务器时出现UnicodeDecodeError:

from flask import Flask

app = Flask(__name__);

app.run();

运行后会出现

D:\Fuwuqi>demo1.py
Traceback (most recent call last):
File "D:\Fuwuqi\demo1.py", line 23, in
app.run();
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", l
ine 841, in run
run_simple(host, port, self, **options)
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\site-packages\werkzeug\serving
.py", line 739, in run_simple
inner()
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\site-packages\werkzeug\serving
.py", line 699, in inner
fd=fd)
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\site-packages\werkzeug\serving
.py", line 593, in make_server
passthrough_errors, ssl_context, fd=fd)
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\site-packages\werkzeug\serving
.py", line 504, in init
HTTPServer.__init__(self, (host, int(port)), handler)
File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 453, in
init
![    self.server_bind()<br>
  File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\http\server.py", line 138, in<br>
server_bind<br>
    self.server_name = socket.getfqdn(host)<br>
  File "C:\Users\顾准\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 673, in getfq<br>
dn<br>
    hostname, aliases, ipaddrs = gethostbyaddr(name)<br>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte<br>
图片图片说明](https://img-ask.csdn.net/upload/201710/31/1509439808_916754.png)说明



编码问题,
文件前面加上这个前缀# -*- coding: utf-8 -*-

凡是UnicodeDecodeError 都是编码问题,在decode()中指定正确的encoding即可。
为避免编码错误,建议在python环境指定编码为utf-8,然后所有其它编码的字节串或者字符串都转成utf-8编程。