Search code examples
pythonpython-unicodeflask-restful

Special characters in Python Flask's reqparse.RequestParser()


When adding the argument as follows

    self.request_parser.add_argument(
        name='address',
        required=True,
        type=str,
        help="Needs argument: 'address' - The address"
    )

where self.request_parser is an instance of reqparse.RequestParser() it works pefectly fine if my request is {'address': 'Gyvelvej'}, but as soon as I add the special character æ as in {'address': 'Torpevænget'} the applications throws an 400 BAD REQUEST, stating that address is missing.

In that case, when printing request.data yields {"address":"Torpevænget"}, so it is present, but apparently not available for reqparse.

Is there any way to make this work?

I'm sending the requests via AngularJS resource, and I would prefer not to alter that code, since I expect this application collaborate with multiple different clients.

EDIT: Answer below


Solution

  • Found the answer my self, after I tagged the question with python-unicode

    Changing type to unicode fixes the problem, i.e.

    self.request_parser.add_argument(
        name='address',
        required=True,
        type=unicode,
        help="Needs argument: 'address' - The address"
    )