Search code examples
python-3.xfalconframework

AttributeError: 'Request' object has no attribute 'params'


I'm getting error " AttributeError: 'Request' object has no attribute 'params' " in falcon library on python3, ubuntu.

request url = 127.0.0.1:8000/user?name=abc

from wsgiref import simple_server
import falcon

class user(object):
    def on_get(self, req, resp):
        print(req.params['name'])

api = application = falcon.API()

usr = user()
api.add_route('/user', usr)

if __name__ == '__main__':
    http = simple_server.make_server('127.0.0.10', 8000, api)
    http.serve_forever()

In the above code I'm unable to access req.params


Solution

  • If you are using version 1.0, be aware of the following breaking change:

    An option was added to toggle automatic parsing of form params. Falcon will no longer automatically parse, by default, requests that have the content type "application/x-www-form-urlencoded"...

    Applications that require this functionality must re-enable it explicitly, by setting a new request option that was added for that purpose, per the example below:

    app = falcon.API()
    app.req_options.auto_parse_form_urlencoded = True
    

    https://github.com/falconry/falcon/blob/master/CHANGES.rst