Skip to Content
Menu
This question has been flagged
3 Replies
6690 Views

I'm writing a controller function that accepts post requests. I need to get the data from the post in the order it was sent to me. It seems like this is possible in werkzeug, by changing the class that the request object uses to store post data, but I can't get it to work in Odoo. I've tried something along these lines:


request.httprequest.parameter_storage_class = werkzeug.datastructures.ImmutableOrderedMultiDict

_logger.warn('form data: %s' % request.httprequest.form)


This outputs the post data, but it's still in the form of an ImmutableMultiDict, not the ordered one.

Avatar
Discard

It seems like the stream is empty. The werkzeug documentation suggests that this can be because the form data has already been parsed (which I suppose it has in Odoo).

Best Answer

You could access to the POST data from the request stream like:

post_data = simplejson.load(request.httprequest.stream)

In this case I parsed into a dict using simplejson, you could read the stream using what best fit your needs since it's a file-like object. Read more at:

http://werkzeug.pocoo.org/docs/0.10/request_data/

Avatar
Discard

I done that in OpenERP v7, but that not change a lot, try to do a request.httprequest.stream.seek(0) if it's already parsed, you should be able to parsed again, it's a file -like object. Otherwise debug at that line to inspect request.httprequest to see where it holds the post data according to werkzeug docs