Falcon: POST value converted to list when contain comma

Created on 13 Sep 2018  路  4Comments  路  Source: falconry/falcon

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']

Most helpful comment

This is working good with api.req_options.auto_parse_qs_csv = False and issue can be closed.

All 4 comments

$ pip3 list | grep falcon
falcon (1.4.1)

This is working good with api.req_options.auto_parse_qs_csv = False and issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mortymacs picture mortymacs  路  5Comments

benzid-wael picture benzid-wael  路  3Comments

houqp picture houqp  路  3Comments

kgriffs picture kgriffs  路  7Comments

neilalbrock picture neilalbrock  路  5Comments