Skip to content

Frequently asked questions

bdarnell edited this page Jun 29, 2012 · 1 revision

Why doesn't RequestHandler.request.arguments interpret JSON POST bodies?

request.arguments and the methods that work with it (get_argument, get_arguments, decode_argument) are designed around the limitations and peculiarities of the x-www-form-encoded format (technically a multimap but typically used as a map, underspecified character encodings, etc). If you weren't saddled with that format to begin with, why try to fit your relatively expressive json data into its constraints?

Just do something like this, and then use self.json_args.get("foo") instead of self.get_argument("foo"):

def prepare(self):
    if self.request.headers.get("Content-Type") == "application/json":
        self.json_args = json_decode(self.request.body)