Search code examples
pythoncherrypy

Distinguish data received via POST and GET in Cherrypy


The variable cherrypy.request.params as it is described in the API contains the query string and the POST variables in a dictionary. However combing over this, it seems that it contains every variable received after processing the full request URI to pull the GET data. This then becomes indistinguishable from POST data in the dictionary. There seems to be no way to tell the difference, or perhaps I am wrong.

Can someone please enlighten me as to how to use purely posted data and ignore any data in the query string beyond the request URI. And yes I am aware I can find out whether it was a POST or GET request but this does not stop forgery in requests to URIs containing GET data in a POST request.

>http://localhost:8080/testURL/part2?test=1
>POST username = test

"cherrypy.request.params" has 2 variables
test = 1
username=test

Solution

  • The docs aren't very clear on this point, but starting in CherryPy 3.2, you can reference request.body.params to obtain just the POST/PUT params. In 3.2 and below, try request.body_params. See http://docs.cherrypy.org/dev/refman/_cprequest.html#cherrypy._cprequest.Request.body_params