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 错误请求?

        How to intentionally cause a 400 Bad Request in Python/Flask?(如何在 Python/Flask 中故意导致 400 错误请求?)
        <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 错误请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

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

                        <tbody id='c8ChA'></tbody>
                        <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>