Axios, POST request to Flask Axios, POST request to Flask flask flask

Axios, POST request to Flask


You need to add CORS support to your Flask app. See a related threat here:Flask-CORS not working for POST, but working for GET. A popular CORS extension for Flask can be found here: https://flask-cors.readthedocs.io/en/latest/.


If anyone else is stuck, be sure to check your before and after request methods. My problem was this:

@app.before_requestdef oauth_verify(*args, **kwargs):    """Ensure the oauth authorization header is set"""    if not _is_oauth_valid():        return some_custome_error_response("you need oauth!")

So then this would raise an exception on any request, including an OPTIONS method. Of course, the fix is easy:

@app.before_requestdef oauth_verify(*args, **kwargs):    """Ensure the oauth authorization header is set"""    if request.method in ['OPTIONS', ]:        return    if not _is_oauth_valid():        return some_custome_error_response("you need oauth!")