title: How to intentionally cause a 400 Bad Request in Python/Flask?
body: <p>A consumer of my REST API says that on occasion I am returning a <code>400 Bad Request</code> - <code>The request sent by the client was syntactically incorrect.</code> error.</p>
  
  <p>My application (Python/Flask) logs don't seem to be capturing this, and neither do my webserver/Nginx logs.</p>
  
  <p>Edit: I would like to try to cause a 400 bad request in Flask for debugging purposes. How can I do this?</p>
  
  <p>Following James advice, I added something similar to the following:</p>
  
  <pre><code>@app.route('/badrequest400')
  def bad_request():
      return abort(400)
  </code></pre>
  
  <p>When I call this, flask returns the following HTML, which doesn't use the "The request sent by the client was syntactically incorrect" line:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  &lt;title&gt;400 Bad Request&lt;/title&gt;
  &lt;h1&gt;Bad Request&lt;/h1&gt;
  &lt;p&gt;The browser (or proxy) sent a request that this server could not understand.&lt;/p&gt;
  </code></pre>
  
  <p>(I'm not sure why it isn't including the <code>&lt;body&gt;</code> tags.</p>
  
  <p>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:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Bad Request&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;
          &lt;p&gt;Bad Request&lt;/p&gt;
      &lt;/h1&gt;
  Error parsing headers: 'limit request headers fields size'
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there a way to get Flask to through the different variations of 400 errors?</p>