I try to make a POST to a flask server using axios:
var config = { headers: {
\'Content-Type\': \'application/json\',
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_request
def 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_request
def 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!")