Axios, POST request to Flask

前端 未结 2 1827
刺人心
刺人心 2021-01-06 17:49

I try to make a POST to a flask server using axios:

var config = { headers: {  
                      \'Content-Type\': \'application/json\',
                        


        
2条回答
  •  醉酒成梦
    2021-01-06 18:50

    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!")
    

提交回复
热议问题