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

About JSON encoding in werkzeug.utils.py #847

Closed
caiz opened this issue Jan 12, 2016 · 3 comments
Closed

About JSON encoding in werkzeug.utils.py #847

caiz opened this issue Jan 12, 2016 · 3 comments

Comments

@caiz
Copy link

caiz commented Jan 12, 2016

def get_content_type(mimetype, charset):
"""Returns the full content type string with charset for a mimetype.
If the mimetype represents text the charset will be appended as charset
parameter, otherwise the mimetype is returned unchanged.
:param mimetype: the mimetype to be used as content type.
:param charset: the charset to be appended in case it was a text mimetype.
:return: the content type.
"""
if mimetype.startswith('text/') or
mimetype == 'application/xml' or
(mimetype.startswith('application/') and
mimetype.endswith('+xml')):
mimetype += '; charset=' + charset
return mimetype

I was just beginning to touch this, have a encoding problems.
Why not judge “mimetype == 'application/json' ”?

@untitaker
Copy link
Contributor

JSON is always UTF-8.

@jacktan1991
Copy link

@caiz there is another discussion: request/request#383, and more details about JSON charset: http://tools.ietf.org/html/rfc4627#section-3

@caiz
Copy link
Author

caiz commented Mar 24, 2016

thank you for your help.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants