def on_post(req, resp, by_id): raw_body = req.stream.read() if not raw_body: raise falcon.HTTPBadRequest('A valid JSON document is required.', '') try: body = json.loads(raw_body.decode('utf-8')) except UnicodeDecodeError: msg = 'Non-UTF8 characters found in the request body' raise falcon.HTTPBadRequest(msg, '') except ValueError as e: msg = 'Could not parse the body as Json: {0}. Ignoring.'.format(e) raise falcon.HTTPBadRequest(msg, '') submitted = Prices.parse(by_id, body) Prices.record(req.context['session'], submitted) resp.add_link('/prices/%s' % by_id, 'self') respond(resp)