m0_37040206
m0_37040206
2018-07-13 12:14
采纳率: 100%
浏览 4.9k

为什么用python写的flask示例程序无法运行,刚刚接触这个,请大佬指教一下

#-*- encoding=UTF-8 -*-
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
return "Hello World!"

if name == '__main__':
app.run()

提示的错误如下:
"F:\pycharm projects\venv\Scripts\python.exe" "F:/pycharm projects/ftest.py"

  • Serving Flask app "ftest" (lazy loading)
  • Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
  • Debug mode: off Traceback (most recent call last): File "F:/pycharm projects/ftest.py", line 11, in app.run() File "F:\pycharm projects\venv\lib\site-packages\flask\app.py", line 943, in run run_simple(host, port, self, **options) File "F:\pycharm projects\venv\lib\site-packages\werkzeug\serving.py", line 814, in run_simple inner() File "F:\pycharm projects\venv\lib\site-packages\werkzeug\serving.py", line 774, in inner fd=fd) File "F:\pycharm projects\venv\lib\site-packages\werkzeug\serving.py", line 660, in make_server passthrough_errors, ssl_context, fd=fd) File "F:\pycharm projects\venv\lib\site-packages\werkzeug\serving.py", line 577, in init self.address_family), handler) File "C:\Users\asus\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 453, in init self.server_bind() File "C:\Users\asus\AppData\Local\Programs\Python\Python36-32\lib\http\server.py", line 138, in server_bind self.server_name = socket.getfqdn(host) File "C:\Users\asus\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 673, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • caozhy
    已采纳

    WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
    这是警告,如果你是在开发测试你的程序,不用理会,只是说,在生产环境中,最好用WSGI

    ipaddrs = gethostbyaddr(name)
    这里的name编码有问题

    点赞 评论
  • caozhy

    你的py文件指定了utf8编码,但是实际文件的编码不是,你用的什么开发工具,找一下编码设置,修改下。

    点赞 评论
  • oyljerry
    oyljerry 2018-07-13 14:11

    机器名称含有其他编码格式的字符,7tf8不能正确解码。最好把机器名改成英文的。

    点赞 评论
  • oyljerry
    oyljerry 2018-07-14 00:12

    flask直接运行,主要是为了debug等,如果要用到真正的产品,需要用wsgi服务器包裹一下,比如用uwsgi,tornado等

    点赞 评论
  • qq_42339655
    申哲 2018-07-20 03:12

    在run()内加上debug=True
    转为调试模式

    点赞 评论
  • weixin_45412589
    weixin_45412589 2019-07-16 10:25

    修改flaskdemo.py最后一行端口号为其他数值,例如5001/8001

    点赞 评论

相关推荐