<p dir="auto">Got error messages if don't access the body data in POST route. And I guess lost connection.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="127.0.0.1 - - [12/Apr/2022 00:39:05] &quot;POST /good HTTP/1.1&quot; 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] &quot;POST /bad HTTP/1.1&quot; 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] code 400, message Bad HTTP/0.9 request type ('{&quot;id&quot;:')
127.0.0.1 - - [12/Apr/2022 00:39:13] &quot;None /bad HTTP/0.9&quot; HTTPStatus.BAD_REQUEST -"><pre class="notranslate"><code class="notranslate">127.0.0.1 - - [12/Apr/2022 00:39:05] "POST /good HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] "POST /bad HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] code 400, message Bad HTTP/0.9 request type ('{"id":')
127.0.0.1 - - [12/Apr/2022 00:39:13] "None /bad HTTP/0.9" HTTPStatus.BAD_REQUEST -
</code></pre></div>
<p dir="auto">Return data both good, but Bad route do something criminal</p>
<p dir="auto">Example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from flask import Flask, request
app = Flask(__name__)

@app.route('/bad', methods=['POST'])
def bad():
    return 'OK'

@app.route('/good', methods=['POST'])
def good():
    # j = request.get_json()  also works
    d = request.data
    return 'OK'

if __name__ == &quot;__main__&quot;:
    app.run(host='127.0.0.1', port=8000, debug=True, use_reloader=False)"><pre class="notranslate"><code class="notranslate">from flask import Flask, request
app = Flask(__name__)

@app.route('/bad', methods=['POST'])
def bad():
    return 'OK'

@app.route('/good', methods=['POST'])
def good():
    # j = request.get_json()  also works
    d = request.data
    return 'OK'

if __name__ == "__main__":
    app.run(host='127.0.0.1', port=8000, debug=True, use_reloader=False)
</code></pre></div>
<p dir="auto">Request 1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST -H 'Content-Type: application/json' -H 'Connection: keep-alive' -d '{&quot;id&quot;: &quot;fo&quot;}' http://127.0.0.1:8000/good -v"><pre class="notranslate"><code class="notranslate">curl -X POST -H 'Content-Type: application/json' -H 'Connection: keep-alive' -d '{"id": "fo"}' http://127.0.0.1:8000/good -v
</code></pre></div>
<p dir="auto">GOOD: no error messages in log</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="127.0.0.1 - - [12/Apr/2022 00:39:05] &quot;POST /good HTTP/1.1&quot; 200 -"><pre class="notranslate"><code class="notranslate">127.0.0.1 - - [12/Apr/2022 00:39:05] "POST /good HTTP/1.1" 200 -
</code></pre></div>
<p dir="auto">Request 2:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST -H 'Content-Type: application/json' -H 'Connection: keep-alive' -d '{&quot;id&quot;: &quot;fo&quot;}' http://127.0.0.1:8000/bad -v"><pre class="notranslate"><code class="notranslate">curl -X POST -H 'Content-Type: application/json' -H 'Connection: keep-alive' -d '{"id": "fo"}' http://127.0.0.1:8000/bad -v
</code></pre></div>
<p dir="auto">BAD:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="127.0.0.1 - - [12/Apr/2022 00:39:13] &quot;POST /bad HTTP/1.1&quot; 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] code 400, message Bad HTTP/0.9 request type ('{&quot;id&quot;:')
127.0.0.1 - - [12/Apr/2022 00:39:13] &quot;None /bad HTTP/0.9&quot; HTTPStatus.BAD_REQUEST -"><pre class="notranslate"><code class="notranslate">127.0.0.1 - - [12/Apr/2022 00:39:13] "POST /bad HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2022 00:39:13] code 400, message Bad HTTP/0.9 request type ('{"id":')
127.0.0.1 - - [12/Apr/2022 00:39:13] "None /bad HTTP/0.9" HTTPStatus.BAD_REQUEST -
</code></pre></div>
<p dir="auto">Environment:</p>
<ul dir="auto">
<li>Python version: 3.8.0</li>
<li>Flask version: Flask 2.1.1, Werkzeug 2.1.1</li>
</ul>
<p dir="auto">With the following example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from flask import Flask

app = Flask(__name__)


@app.route('/', methods=['POST'])
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">flask</span> <span class="pl-k">import</span> <span class="pl-v">Flask</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Flask</span>(<span class="pl-s1">__name__</span>)


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">route</span>(<span class="pl-s">'/'</span>, <span class="pl-s1">methods</span><span class="pl-c1">=</span>[<span class="pl-s">'POST'</span>])</span>
<span class="pl-k">def</span> <span class="pl-en">hello_world</span>():
    <span class="pl-k">return</span> <span class="pl-s">'Hello World!'</span>


<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-s1">app</span>.<span class="pl-en">run</span>()</pre></div>
<p dir="auto">When you set the request body to <code class="notranslate">{}</code> with Postman or any HTTP clients, the first request will return 200, while the second request will return a 405 error response. The log shows the request method is <code class="notranslate">{}POST</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;{}POST / HTTP/1.1&quot; 405"><pre class="notranslate"><code class="notranslate">"{}POST / HTTP/1.1" 405
</code></pre></div>
<p dir="auto">Notice the request body became the part of the request method.</p>