My code :
# serve.py
import falcon
def max_body(limit):
def hook(req, resp, resource, params):
length = req.content_length
if length is not None and length > limit:
msg = ('The size of the request is too large. The body must not '
'exceed ' + str(limit) + ' bytes in length.')
raise falcon.HTTPRequestEntityTooLarge(
'Request body is too large', msg)
return hook
class SentimentResource:
@falcon.before(max_body(64 * 2048))
def on_post(self, req, resp):
"""Handles API requests"""
try:
text = req.params['text']
print(text) # [] / ""
except KeyError:
raise falcon.HTTPBadRequest(
'Missing thing',
'A thing must be submitted in the request body.')
resp.media = text
api = falcon.API()
api.req_options.auto_parse_form_urlencoded = True
api.add_route('/', SentimentResource())
request :
curl -d "text=sometime i feel better, and then idk why" http://localhost:8000
logger :
you@pc: gunicorn serve:api
[2018-09-13 18:51:41 +0700] [21338] [INFO] Starting gunicorn 19.9.0
[2018-09-13 18:51:41 +0700] [21338] [INFO] Listening at: http://127.0.0.1:8000 (21338)
[2018-09-13 18:51:41 +0700] [21338] [INFO] Using worker: sync
[2018-09-13 18:51:41 +0700] [21341] [INFO] Booting worker with pid: 21341
['sometime i feel better', ' and then idk why']
$ pip3 list | grep falcon
falcon (1.4.1)
does this help? https://falcon.readthedocs.io/en/latest/user/faq.html#id31
maybe a bug in the docs, see https://github.com/falconry/falcon/pull/1354/commits/070d73b645384baf4789ddb23db2b263d9bb3750
This is working good with api.req_options.auto_parse_qs_csv = False and issue can be closed.
Most helpful comment
This is working good with
api.req_options.auto_parse_qs_csv = Falseand issue can be closed.