POST application/xml 415 not supporter

1,030 views
Skip to first unread message

Michele Lazzeri

unread,
Dec 6, 2011, 1:14:09 PM12/6/11
to django-rest-framework
Hi,

I'd like to expose in my django applicaction a POST service which can
receive JSON and XML

I'm able to POST JSON but if I try to POST XML I receive a "415
Unsupported content type"

Furthermore, I install the object-store expample. In the online demo
http://api.django-rest-framework.org/object-store/ the content type
combo appear "application/xml" but in my local installation disappear.

What's wrong? Do I miss any libraries?

Micheòe

Marko Tibold

unread,
Dec 7, 2011, 9:04:41 AM12/7/11
to django-res...@googlegroups.com
Hi,

when you POST against the example api do you see the same behavior? http://api.django-rest-framework.org/blog-post/

Michele Lazzeri

unread,
Dec 7, 2011, 10:23:02 AM12/7/11
to django-res...@googlegroups.com
Hi,

thanks for your reply. do you mean the online demo of object store http://api.django-rest-framework.org/object-store/ ?

I put here my curl test execution:

- object store demo in my local installation

curl -X POST -H "Content-Type: application/xml" --data-binary '<content>1</content>' http://localhost:8000/object-store/
{"error": "Unsupported media type in request 'application/xml'."}

- object store demo online

curl -X POST -H "Content-Type: application/xml" --data-binary '<content>1</content>' http://api.django-rest-framework.org/object-store/

Response 500, the django error debug output says "max_file not defined". Ok this is a error but the POST is executed

So, I'm sure that example loaded in  http://api.django-rest-framework.org/object-store/ differs from the object-store source code example.

P.S.

I try also to post a xml to blog-post example but doesn't work, probably the form validation block the POST

curl -X POST -H "Content-Type: application/xml" --data-binary '<content>1</content>' http://api.django-rest-framework.org/blog-post/

Marko Tibold

unread,
Dec 8, 2011, 10:18:06 AM12/8/11
to django-res...@googlegroups.com
Hi Michele,

I'm sorry for the slow reply. Currently I'm busier than I like to be.

Taking a closer look, POSTing xml data is not supported as far as I see. There's no XML parser in the framework. You can only render to XML.

I beleave it is common practice to either use 'application/json' or 'apllication/x-www-form-urlencoded'. The latter being the default curl uses.

It's a bit confusing to be able to render to xml but not parse it, that is not being able to handle requests that are xml-serialized.

Maybe Tom can tell some more on that subject when he has the time.

Cheers,

Marko

Tom Christie

unread,
Dec 8, 2011, 12:18:30 PM12/8/11
to django-res...@googlegroups.com
Thanks Marco!

Yup parsing XML isn't supported. (Out of the box, anyways...)

I've taken a look, and the version that's up on the live test site, http://api.django-rest-framework.org, is out of date and still has a (non-functioning) xml parser, which is why the object store example there is confusing.  If you run the example from trunk it won't display XML as an option.

Def agree that it's a bit confusing to have xml rendering but not xml parsing, tho TBH the xml rendering is more there as an example that you can render in various different formats, as opposed to expecting that anyone would actually want to use it.  Anyone who does have a good reason for using XML over JSON is probably going to have some requirements about the XML structure that they use so will probably be needing to write a custom renderer/parser anyways.

It'd be good to update the live example sometime, I guess that's something I might feasibly find the time to do sometime... 

Marko Tibold

unread,
Dec 9, 2011, 10:04:13 AM12/9/11
to django-res...@googlegroups.com
I was thinking, maybe to host a tip and a 'release' version. I have plenty of room left on my webfaction account. Could even consider using post_commit_hooks of github to update tip on the webserver and have it restarted. A little geekish but a nice setup I think...

Craig Blaszczyk

unread,
Jan 5, 2012, 5:38:38 AM1/5/12
to django-res...@googlegroups.com
XML Parsing of incoming requests is now supported in django-rest-framework github version (https://github.com/tomchristie/django-rest-framework)

Michele Lazzeri

unread,
Jan 10, 2012, 1:12:10 PM1/10/12
to django-res...@googlegroups.com
Starting from Graig code I have implemented a recursive xml parsing which is the reverse of xml
renderer.

That means: if you GET a "application/xml" from a complex python object with nested dictonary and
array, and then you POST the xml, you'll receive the same complex python object...

Do you think it's useful? If so, where I can send this code?

Tom Christie

unread,
Jan 11, 2012, 7:55:00 AM1/11/12
to django-res...@googlegroups.com
I don't use the XML rendering/parsing myself, so I'm probably not the best person to review it, but sounds good.
Craig might be the best person to review if it's an improvement over what we currently have?

You'd want to fork the github repository and make a pull request.
GitHub's got a bunch of useful help, if you're new to it.

Craig Blaszczyk

unread,
Jan 11, 2012, 10:13:34 AM1/11/12
to django-res...@googlegroups.com
I'll be happy to review the pull request

2012/1/11 Tom Christie <christ...@gmail.com>
Reply all
Reply to author
Forward
0 new messages