Flask-restful: Umlauts in POST requests?

Created on 28 Apr 2014  Â·  3Comments  Â·  Source: flask-restful/flask-restful

When posting an umlaut (ä,ü,ö etc.) to an api-endpoint, i get the following error message:

{"message": "'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)"}

it's a BAD REQUEST status code…

here is my arguments parser code:

parser = reqparse.RequestParser()
parser.add_argument('id', type=str)
parser.add_argument('title', type=str)
parser.add_argument('body', type=str)
parser.add_argument('segment', type=str)
parser.add_argument('mentors', type=str)

any advice how to fix this? thanks…

Most helpful comment

It's an encoding problem. Umlaut are not in the range of the ASCII table. Should be unicode
http://blog.abhijeetr.com/2013/10/encoding-and-python-unicodedecodeerror.html

You should use type=unicode instead type=str when you want to use special characters.

All 3 comments

It's an encoding problem. Umlaut are not in the range of the ASCII table. Should be unicode
http://blog.abhijeetr.com/2013/10/encoding-and-python-unicodedecodeerror.html

You should use type=unicode instead type=str when you want to use special characters.

Don't specify type at all. It defaults to unicode

Both @SBillion and @johnwlockwood are correct. Closing as fixed.

Was this page helpful?
0 / 5 - 0 ratings