提问人:dot 提问时间:9/19/2023 最后编辑:dot 更新时间:11/8/2023 访问量:132
FlaskWebGUI 地址“拒绝连接”+ 缺少“environ”和“start_response”
flaskwebgui address "refused to connect" + missing 'environ' and 'start_response'
问:
我有一个基本的烧瓶应用程序:
from flask import Flask
import flaskwebgui
app = Flask(__name__)
gui = flaskwebgui.FlaskUI(app)
@app.route("/")
def hello():
return "Hello"
if __name__ == "__main__":
gui.run()
使用代替按预期工作。没有错误,我得到一个 localhost 链接,我可以单击该链接查看该站点。app.run()
gui.run()
但是,如果我执行上述示例中所做的操作,则我的输出会得到以下结果:
path to chrome not found
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
Command: python3 -m webbrowser -n http://127.0.0.1:33951
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
TypeError: Flask.__call__() missing 2 required positional arguments: 'environ' and 'start_response'
我设法通过下载 chromium AppImage 并将 FlaskUI 修改为:
gui = flaskwebgui.FlaskUI(app, browser_path="./chrome.AppImage")
现在,这是输出:
ofstuff/b0unce¡t/app.py
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
Command: ./chrome.AppImage --user-data-dir=/tmp/flaskwebgui --new-window --no-first-run --start-maximized --app=http://127.0.0.1:40077
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
TypeError: Flask.__call__() missing 2 required positional arguments: 'environ' and 'start_response'
/snap/core20/current/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libproxy.so.1)
Failed to load module: /home/simon/snap/code/common/.cache/gio-modules/libgiolibproxy.so
Gtk-Message: 14:36:18.659: Failed to load module "canberra-gtk-module"
Gtk-Message: 14:36:18.662: Failed to load module "canberra-gtk-module"
[24939:24939:0919/143618.957750:ERROR:policy_logger.cc(154)] :components/enterprise/browser/controller/chrome_browser_cloud_management_controller.cc(163) Cloud management controller initialization aborted as CBCM is not enabled.
[24939:24939:0919/143619.954445:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.portal.Settings.Read: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files
Fontconfig error: Cannot load default config file: No such file: (null)
一个没有标签的镶边窗口会像我所期望的那样打开,但它找不到地址:127.0.0.1 refused to connect.
我在 Ubuntu 22.04.03 上的 Visual Studio Code 中的 python venv 中
答:
0赞
Stradatek Inc
11/8/2023
#1
您可以通过在初始化 FlaskUI 时添加 app=app 和 server=“flask” 作为参数来解决此问题。
from flask import Flask
from flaskwebgui import FlaskUI
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello"
if __name__ == '__main__':
FlaskUI(app=app, server="flask", width=800, height=600).run()
评论