I have a Python flask backend that returns JSON. Every time I make a POST request that returns a 401 (because tokens have expired) it then prepends the JSON body data to the next request, which causes a 405 method not allowed because as you can see, the data is showing where the method should be. This is the same issue as this post for Django
This is the log from my local:
127.0.0.1 - - [25/May/2022 08:17:01] "POST /stsatellites/filter HTTP/1.1" 401 -
127.0.0.1 - - [25/May/2022 08:17:29] "OPTIONS /auth/login HTTP/1.1" 200 -
127.0.0.1 - - [25/May/2022 08:17:29] "{"filters":[{"field":"NORAD_CAT_ID","op":"eq","value":25165}]}POST /auth/login HTTP/1.1" 405 -
Here are screenshots of the requests, as you can see that filter data originated on the first request which got the 401 response. Filter POST Filter POST Payload
Following Login request: Login POST Headers Login POST Payload
We have a workaround in place which resolves this issue but it's a band-aid that I would like to remove. For some reason the request.get_data
method fixes the caching issue.
@app.after_request
def after_request_func(response):
if response.status == "401 UNAUTHORIZED":
request.get_data(cache=False)
return response