I'm attempting to use requests to POST form-data and need to check the status code of the POST request itself, however despite specifying allow_redirects=False
, the request is still redirecting to a GET request, which returns a status code of 200
, rather than the POST's status code of 302
.
Note: I have tested the exact same POST request in Postman with automatic redirects turned off and am getting expected behaviour.
Edit:
I was able to find a property called strict_mode
on Requests' PyPi page here
I managed to find this on the french requests docs by using an absolute search for strict_mode
on Google, however the same place on the English docs doesn't list the property.
Here's an excerpt from the French docs that pertains to my question:
strict_mode: If true, Requests will do its best to follow RFCs (e.g. POST redirects).
Edit 2:
I've found this regarding strict_mode
on the requests github repo:
https://github.com/psf/requests/commit/95a03532c36f1afd38c395f7160c7f7086557b7b
It appears to have been removed since 2012 so, is there a way to bypass this that isn't hacky?
Originally posted this as an answer before finding that it didn't work:
It appears that I'll have to do something similar to this: https://github.com/psf/requests/issues/1325
I found this on google: https://subscription.packtpub.com/book/networking_and_servers/9781784395414/1/ch01lvl1sec18/tracking-redirection-of-the-request-using-request-history
For anyone else with this issue it shows how to get a list of previous statuses when being redirected
Edit:
Just tried implementing this, history is blank even with allow redirects set to true. I'm not sure how Postman can get the 302 code, Chrome dev tools can get the correct code when viewing the network tab, but requests can't.