flassger自动验证(验证=真)

2024-05-15 21:48:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想向社区寻求关于在python(v3)上使用flasger的帮助 目前我正在使用Flasger和Flask Restplus(虽然Flask resplus确实有自己的招摇过市,但我更喜欢使用Flasger)。 不管怎样,我的问题是在@swag_from中打开“validation=True”时。 这是我的代码片段。在

Python代码:

@api.route("/v1/cancels")
class Cancels(Resource):
    @swag_from(v1swag["cancels_post"], validation=True)
    def post(self):
        token = request.form.get("token")
        <...>
        message = {
            "message": "ok",
            "token": token
        }
        return jsonify(message)

招摇过市(json)

^{pr2}$

问题是如果只使用@swag_from(v1swag[“cancels_post”]),那么一切都会正常工作(除了验证)。我的意思是交易成功完成。在

如果我将其设置为@swag_from(v1swag[“cancels_post”],validation=True) 我得到。。。在

Response Body
{
  "message": "The browser (or proxy) sent a request that this server could not understand."
}
Response Code
400

我也试过了

"in": "formData"

但是有这些吗

Response Body
No data to validate
Response Code
500
Response Headers
{
  "access-control-allow-origin": "http://192.168.1.236:4000",
  "date": "Fri, 14 Jul 2017 08:58:19 GMT",
  "server": "gunicorn/19.7.1",
  "connection": "keep-alive",
  "content-length": "19",
  "vary": "Origin",
  "content-type": "text/html; charset=utf-8"
}

你能解释一下我面临的这个问题吗。我仍然找不到可以帮助我解决问题的链接。在

提前谢谢大家。在


Tags: 代码fromtokentrueflaskmessageresponserequest