Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unicode LookupError #159

Merged
merged 1 commit into from
Dec 17, 2013

Conversation

singingwolfboy
Copy link
Contributor

six.text_type is unicode on Python 2 and str on Python 3. Both of these
functions accept multiple parameters: the second is the encoding parameter.
According to the documentation: "The encoding parameter is a string giving the
name of an encoding; if the encoding is not known, LookupError is raised."
Because LookupError does not inherit from TypeError, it is not caught by
the try/catch blocks, and can result in Flask-Restful returning a 400 status
code response.

This commit changes the default type to a wrapper around six.text_type that
only takes one parameter. This way, an encoding will never be specified, and it
will never raise a LookupError.

`six.text_type` is `unicode` on Python 2 and `str` on Python 3. Both of these
functions accept multiple parameters: the second is the `encoding` parameter.
According to the documentation: "The encoding parameter is a string giving the
name of an encoding; if the encoding is not known, `LookupError` is raised."
Because `LookupError` does not inherit from `TypeError`, it is not caught by
the try/catch blocks, and can result in Flask-Restful returning a 400 status
code response.

This commit changes the default type to a wrapper around `six.text_type` that
only takes one parameter. This way, an encoding will never be specified, and it
will never raise a `LookupError`.
@kevinburke
Copy link
Contributor

LGTM. Thanks!

@kevinburke
Copy link
Contributor

Wondering if we should move this to types.py to avoid the lambda..

kevinburke pushed a commit that referenced this pull request Dec 17, 2013
@kevinburke kevinburke merged commit 05166ca into flask-restful:master Dec 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants