【问题标题】:Google Cloud Run unlogged 502 responses for DEL requestsGoogle Cloud Run 未记录 DEL 请求的 502 响应
【发布时间】:2021-06-12 16:28:11
【问题描述】:

我创建了一个非常简单的 Google Cloud Run Python 服务来试验 Restful API:

import os
from flask import Flask

app = Flask(__name__)

@app.route('/user/<user_name>', methods=['PUT'])
def create_user(user_name):
    return 'created!', 200

@app.route('/user/<user_name>', methods=['DEL'])
def delete_user(user_name):
    return 'deleted!', 200

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

我已成功使用此Dockerfile 将此服务部署到 Cloud Run。

为了测试服务,我使用curl 来访问已部署的端点:

$curl -X PUT https://testapi.xxxxxxxx.a.run.app/user/prl900
created!

但是,DEL 请求会导致 502 错误,并且神秘地没有记录在 Cloud Run 的日志记录平台中。

$curl -X DEL https://testapi.xxxxxxxx.a.run.app/user/prl900
...
...
<p><b>502.</b> <ins>That’s an error.</ins>
  <p>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.  <ins>That’s all we know.</ins>

所有其他方法都被拒绝并正确记录在后端,正如预期的那样:

$curl -X PATCH https://testapi.xxxxxxxx.a.run.app/user/prl900
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

谁能理解 Cloud Run 无法处理 DEL 请求并且没有记录它们的原因? Cloud Run 上的 DEL 请求有什么特别之处吗?该服务在我的本地计算机上运行良好。

感谢您的帮助

【问题讨论】:

    标签: python gunicorn flask-restful google-cloud-run http-delete


    【解决方案1】:

    正确的 HTTP 动词是 DELETE 而不是 DEL。您需要将烧瓶路线更改为:

    @app.route('/user/<user_name>', methods=['DELETE'])
    

    然后正确的 curl 命令将是:

    curl -X DELETE https://testapi.xxxxxxxx.a.run.app/user/prl900
    

    使用非标准动词会导致位于您服务前面的 gcloud 基础架构中的某些代理拒绝路由请求。这解释了 502(坏网关)以及日志不显示的原因(它永远不会到达您的服务)。

    【讨论】:

    • 谢谢@Matthew,这是有道理的。由于该服务在我的本地计算机上运行,​​因此令人困惑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 2019-12-20
    相关资源
    最近更新 更多