应用程序引擎Flask应用程序:进程已终止,因为超过了请求截止日期.(错误代码123)



我正在尝试将flask应用程序部署到应用程序引擎标准。

该应用程序在我的本地机器上运行良好。

它还部署到应用程序引擎ok。

但是,当我请求URL时,页面没有加载,日志中出现以下消息:

App Engine: Process terminated because the request deadline was exceeded. Please ensure that your HTTP server is listening for requests on 0.0.0.0 and on the port defined by the PORT environment variable. (Error code 123)

我不会分享整个应用程序的代码,但我在其中使用以下app.run命令:

if __name__ == '__main__':
app.run(host='0.0.0.0')

此外,以下是截至GCP日志资源管理器中超过最后期限消息的所有日志消息:

2022-07-26 11:47:00.542 BST
App Initialising
2022-07-26 11:47:00.544 BST
* Serving Flask app 'app' (lazy loading)
2022-07-26 11:47:00.544 BST
* Environment: production
2022-07-26 11:47:00.544 BST
WARNING: This is a development server. Do not use it in a production deployment.
2022-07-26 11:47:00.544 BST
Use a production WSGI server instead.
2022-07-26 11:47:00.544 BST
* Debug mode: off
2022-07-26 11:47:00.556 BST
* Running on all addresses (0.0.0.0)
2022-07-26 11:47:00.556 BST
WARNING: This is a development server. Do not use it in a production deployment.
2022-07-26 11:47:00.556 BST
* Running on http://127.0.0.1:5000
2022-07-26 11:47:00.556 BST
* Running on http://169.254.8.1:5000 (Press CTRL+C to quit)
2022-07-26 11:49:31.899 BST
[start] 2022/07/26 10:49:31.898979 Quitting on terminated signal
2022-07-26 11:49:31.899 BST
[start] 2022/07/26 10:49:31.899629 Start program failed: failed to detect app after start: ForAppStart(): [aborted, context canceled. subject:"app/valid" Timeout:30m0s, attempts:119910 aborted, context canceled. subject:"app/invalid" Timeout:30m0s, attempts:119886]

在这里我测试GET请求应用程序主页:

2022-07-26 11:50:43.136 BST
GET 500 301.663 s Chrome 103.0.0.0 /
188.221.25.131 - - [26/Jul/2022:03:50:43 -0700] GET / HTTP/1.1 500 - - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "<<app url>>" ms=301663 cpu_ms=0 cpm_usd=0 loading_request=0 instance=00c61b117cc57f1885aa1e4f9a85f795df32ab91d3ed079eeaf27721ad7817ec20ebabd30ca9d4226dd67175724a624eba33cd2da0023671d18f app_engine_release=1.9.71 trace_id=2ef242690a4b068b13493764e6279eb2

导致消息超时:

**2022-07-26 11:55:44.799 BST
Process terminated because the request deadline was exceeded. Please ensure that your HTTP server is listening for requests on 0.0.0.0 and on the port defined by the PORT environment variable. (Error code 123)**

有人知道可能是什么问题吗?或者有人能为我指明进一步探索的正确方向吗?

必须将app.run上的端口值更改为8080,如@John Hanley注释所示:

默认端口为8080。Flask监听端口5000。更改您的代码:

app.run(host='0.0.0.0', port=8080)

如Flask文档所示,Flask在端口5000:上运行

要运行应用程序,请使用flash命令。。。

$ flask run
* Running on http://127.0.0.1:5000/

因此,必须将其更改为在端口8080上运行,如在应用程序引擎灵活环境文档中创建Python应用程序示例代码:中所述

# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
# Flask's development server will automatically serve static files in
# the "static" directory. See:
# http://flask.pocoo.org/docs/1.0/quickstart/#static-files. Once deployed,
# App Engine itself will serve those files as configured in app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)

相关内容

最新更新