Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django REST: Unsupported media type 'application/xml' in request

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.

like image 502
Prometheus Avatar asked Feb 14 '13 12:02

Prometheus


2 Answers

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.

like image 199
Tom Christie Avatar answered Oct 21 '22 05:10

Tom Christie


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.

like image 45
ssidorenko Avatar answered Oct 21 '22 07:10

ssidorenko