简体   繁体   中英

Flask API blocking OPTIONS requests

I have an API written in Flask, when I am trying to use this API from AngularJS I am getting an 401 error unauthorized, same request with same credentials is working fine from Postman or HTTPie. This is happening with GET or POST request.

I noticed that the difference between HTTPie and Angular request is that Angular is calling OPTIONS before a GET request.

This is my python code where authentication is required(api is a blueprint):

@api.before_request
@rate_limit(limit=5, period=15)
@auth_token.login_required
def before_request():
   """All routes in this blueprint require authentication."""
   pass

The only method that is working from my api is one that is outside of this blueprint, my conclusion is that the @api.before_request and @auth_token.login_required are expecting credentials to be sent for the OPTIONS request, any idea what can I do?

Thank you very much

I figure out the problem, I solved after updating the plugin Flask-HTTPAuth.

I was having the version 2.2.1 and after moving to 3.2.1 it solved.

Tried the same on an instance of Amazon EC2 and solved with the same solution so I am quite sure it was this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM