I'm using http://django-rest-framework.org/ Tokens and trying to now get a token. I have followed the guides. However,
When I try to make a post to the URL:
Request Url: http://127.0.0.1:8001/api-token-auth/
Request Method: POST
Status Code: 415
Params: {
"username": "test",
"password": "test123"
}
I get the following response
{
"detail": "Unsupported media type 'application/xml' in request."
}
Why is this?
Thank you.
Looks like you're sending a request using XML content.
As the docs note, the obtain_auth_token view expect a JSON request.
Make sure the data is JSON encoded, and that you're correctly setting the 'Content-Type' header to 'application/json
.
It's because django-rest-framework can return data in more than one format. It apparently decides on which format by looking at the "Accept:" HTTP header in the request. Try changing the value of this header to something like "application/json" for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With