Axios POST request fails with error status code 500: Internal Server error : <p>I'm trying to send a POST request locally with a username and password in the body through Axios. </p>

<p>I'm deploying a Flask app on <a href="http://127.0.0.1:5000/login" rel="noreferrer">http://127.0.0.1:5000/login</a>, which handles the /login route. The POST request fails with the following error</p>

<pre class="lang-js prettyprint-override"><code>POST http://127.0.0.1:5000/login 500 (INTERNAL SERVER ERROR)
Error: Request failed with status code 500
    at createError (createError.js:16)
    at settle (settle.js:18)
    at XMLHttpRequest.handleLoad (xhr.js:77)
</code></pre>



<p>I researched a bit and thought it might be a problem with CORS, but this doesn't seem to be the case because I tried an Axios GET request and it worked fine (response logged properly). Here's part of my code</p>

<pre class="lang-js prettyprint-override"><code>axios.get("http://127.0.0.1:5000").then(function(response) {
        console.log(response);
      }).catch(function(error) {
        console.log(error);
      })
axios.post("http://127.0.0.1:5000/login", {
        username: this.state.username,
        password: this.state.password
      }).then(function(response) {
        console.log(response);
      }).catch(function(error) {
        console.log(error);
      })
</code></pre>

<p>
Looking at Chrome DevTools, I can see that the POST request payload is properly populated. I then tried printing out the keys server-side in the Flask app using the following code, but I got nothing, empty. (which was expected since the POST request failed)</p>

<pre class="lang-js prettyprint-override"><code>dict = request.form
    for key in dict:
        print('form key '+dict[key])
</code></pre>



<p>HOWEVER using Postman with the corresponding keys and values works properly and returns a response and prints out the keys (see above). Where is the failure coming from? Why would the POST request fail when a GET seems to work just fine?</p>
