Issue
I have set up django-rest-auth as per the installation tutorial, yet I am not able to use the login API endpoint. When I send a POST request with the correct information, I receive a 405 status error in response with "Method "GET" not allowed."
However, when I navigate to the actual URL and POST it from the online form, it works fine and returns a token.
Help?!
Example with Postman:
https://i.imgur.com/574rERm.png
Example with Axios:
axios.post('http://----.com/api/accounts/login/', data: {'username': ---, 'password': ---})
.then(function (response) {console.log(response);})
.catch(function (response) {console.log(response);})
UPDATE:
This seems to be an issue with possibly Heroku or Gunicorn? The website is deployed on Heroku using Gunicorn, but all POST Requests are being received as GET requests.
Solution
For anyone coming across this strange phenomenon of a POST request turning into a GET request mysteriously...
I'm using Django + DRF on Heroku. The problem was so simple it made me want to laugh and cry at the same time.
Heroku redirects requests to http://example.com to http://www.example.com, and this redirection involves a GET request. As a result, the POST request is received as a GET request without any of the headers or body that was initially present.
All of that work and frustration just for a missing 'www'. Hope this helps somebody in the future!
https://stackoverflow.com/a/23688973/8407856
Answered By - Priyam Mohanty
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.