加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用 Flask 报错

发布时间:2020-12-20 10:48:07 所属栏目:Python 来源:网络整理
导读:一、跟着写了一个很简单的Flask应用,直接报错 from flask import Flaskapp = Flask(__name__)@app.route( " / " )def hello(): return " 1234 " if __name__== " __main__ " : app.run() 报的错误 Traceback (most recent call last): File " input " ,line

一、跟着写了一个很简单的Flask应用,直接报错

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "1234"
if __name__=="__main__":
    app.run()

报的错误

Traceback (most recent call last):
  File "<input>",line 1,in <module>
  File "D:pythoninstallhelperspydev_pydev_bundlepydev_umd.py",line 197,in runfile
    pydev_imports.execfile(filename,global_vars,local_vars)  # execute the script
  File "D:pythoninstallhelperspydev_pydev_imps_pydev_execfile.py",line 18,in execfile
    exec(compile(contents+"n",file,exec),glob,loc)
  File "E:/Python/UseTest.py",line 8,in <module>
    app.run()
  File "C:UsersyouzikuAppDataRoamingPythonPython36site-packagesflaskapp.py",line 990,in run
    run_simple(host,port,self,**options)
  File "C:UsersyouzikuAppDataRoamingPythonPython36site-packageswerkzeugserving.py",line 1009,in run_simple
    inner()
  File "C:UsersyouzikuAppDataRoamingPythonPython36site-packageswerkzeugserving.py",line 962,in inner
    fd=fd,File "C:UsersyouzikuAppDataRoamingPythonPython36site-packageswerkzeugserving.py",line 805,in make_server
    host,app,request_handler,passthrough_errors,ssl_context,fd=fd
  File "C:UsersyouzikuAppDataRoamingPythonPython36site-packageswerkzeugserving.py",line 698,in __init__
    HTTPServer.__init__(self,server_address,handler)
  File "C:Program Files (x86)Microsoft Visual StudioSharedPython36_64libsocketserver.py",line 453,in __init__
    self.server_bind()
  File "C:Program Files (x86)Microsoft Visual StudioSharedPython36_64libhttpserver.py",line 138,in server_bind
    self.server_name = socket.getfqdn(host)
  File "C:Program Files (x86)Microsoft Visual StudioSharedPython36_64libsocket.py",line 673,in getfqdn
    hostname,aliases,ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: utf-8 codec cant decode byte 0xb3 in position 8: invalid start byte

这个雷我踩了两天,现在记录一下,易产生错误的点

1)是代码的编码问题,将页面重新保存设为 utf-8。

2)电脑的名字是中文,以及用户名是中文

3)端口被占用手动指定端口即可

当前两个没用时,不妨指定一下端口

if __name__ == __main__:
    app.run(host="0.0.0.0",debug=True,port=9999)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读