1. <i id='IMNtO'><tr id='IMNtO'><dt id='IMNtO'><q id='IMNtO'><span id='IMNtO'><b id='IMNtO'><form id='IMNtO'><ins id='IMNtO'></ins><ul id='IMNtO'></ul><sub id='IMNtO'></sub></form><legend id='IMNtO'></legend><bdo id='IMNtO'><pre id='IMNtO'><center id='IMNtO'></center></pre></bdo></b><th id='IMNtO'></th></span></q></dt></tr></i><div id='IMNtO'><tfoot id='IMNtO'></tfoot><dl id='IMNtO'><fieldset id='IMNtO'></fieldset></dl></div>
    2. <legend id='IMNtO'><style id='IMNtO'><dir id='IMNtO'><q id='IMNtO'></q></dir></style></legend>
        • <bdo id='IMNtO'></bdo><ul id='IMNtO'></ul>

        <tfoot id='IMNtO'></tfoot>

        <small id='IMNtO'></small><noframes id='IMNtO'>

        如何在 Python/Flask 中故意导致 400 错误请求?

        时间:2023-09-28
        <legend id='L3mQQ'><style id='L3mQQ'><dir id='L3mQQ'><q id='L3mQQ'></q></dir></style></legend>
        <i id='L3mQQ'><tr id='L3mQQ'><dt id='L3mQQ'><q id='L3mQQ'><span id='L3mQQ'><b id='L3mQQ'><form id='L3mQQ'><ins id='L3mQQ'></ins><ul id='L3mQQ'></ul><sub id='L3mQQ'></sub></form><legend id='L3mQQ'></legend><bdo id='L3mQQ'><pre id='L3mQQ'><center id='L3mQQ'></center></pre></bdo></b><th id='L3mQQ'></th></span></q></dt></tr></i><div id='L3mQQ'><tfoot id='L3mQQ'></tfoot><dl id='L3mQQ'><fieldset id='L3mQQ'></fieldset></dl></div>

        <tfoot id='L3mQQ'></tfoot>

            <tbody id='L3mQQ'></tbody>

            <small id='L3mQQ'></small><noframes id='L3mQQ'>

              • <bdo id='L3mQQ'></bdo><ul id='L3mQQ'></ul>
                • 本文介绍了如何在 Python/Flask 中故意导致 400 错误请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  A consumer of my REST API says that on occasion I am returning a 400 Bad Request - The request sent by the client was syntactically incorrect. error.

                  My application (Python/Flask) logs don't seem to be capturing this, and neither do my webserver/Nginx logs.

                  Edit: I would like to try to cause a 400 bad request in Flask for debugging purposes. How can I do this?

                  Following James advice, I added something similar to the following:

                  @app.route('/badrequest400')
                  def bad_request():
                      return abort(400)
                  

                  When I call this, flask returns the following HTML, which doesn't use the "The request sent by the client was syntactically incorrect" line:

                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
                  <title>400 Bad Request</title>
                  <h1>Bad Request</h1>
                  <p>The browser (or proxy) sent a request that this server could not understand.</p>
                  

                  (I'm not sure why it isn't including the <body> tags.

                  It appears to me that there are different variations of the 400 error message. For example, if I set a cookie to a value of length 50,000 (using Interceptor with Postman), I'll get the following error from Flask instead:

                  <html>
                  <head>
                      <title>Bad Request</title>
                  </head>
                  <body>
                      <h1>
                          <p>Bad Request</p>
                      </h1>
                  Error parsing headers: 'limit request headers fields size'
                  
                  </body>
                  </html>
                  

                  Is there a way to get Flask to through the different variations of 400 errors?

                  解决方案

                  You can use abort to raise an HTTP error by status code.

                  from flask import abort
                  @app.route('/badrequest400')
                  def bad_request():
                      abort(400)
                  

                  这篇关于如何在 Python/Flask 中故意导致 400 错误请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Postman、Python 以及将图像和元数据传递给 Web 服务 下一篇:如何修复&lt;响应 500&gt;python请求中的错误?

                  相关文章

                    <small id='c8ChA'></small><noframes id='c8ChA'>

                    <legend id='c8ChA'><style id='c8ChA'><dir id='c8ChA'><q id='c8ChA'></q></dir></style></legend>

                    <i id='c8ChA'><tr id='c8ChA'><dt id='c8ChA'><q id='c8ChA'><span id='c8ChA'><b id='c8ChA'><form id='c8ChA'><ins id='c8ChA'></ins><ul id='c8ChA'></ul><sub id='c8ChA'></sub></form><legend id='c8ChA'></legend><bdo id='c8ChA'><pre id='c8ChA'><center id='c8ChA'></center></pre></bdo></b><th id='c8ChA'></th></span></q></dt></tr></i><div id='c8ChA'><tfoot id='c8ChA'></tfoot><dl id='c8ChA'><fieldset id='c8ChA'></fieldset></dl></div>

                      • <bdo id='c8ChA'></bdo><ul id='c8ChA'></ul>
                      <tfoot id='c8ChA'></tfoot>