-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[Python] Skip utf8 decoding for specific Content-Types in py3 #206
Comments
Same issue here (FlatIO/api-client-python#1), I believe a whitelist of mime-types could be helpful here. |
@gierschv thanks, nice to have a second opinion on this. Are you already working to fix this upstream for your project (here)? I wanted to point out that my suggestion needs a change, Whitelist should be checked against I think I can tackle this but I'll need to check how this is solved for other languages in the openapi-generator for consistency. |
No, I didn't have time to work on this, I found this issue by looking into another bug. Another idea for the whitelist: we could have |
I've pushed a PR that I think addresses this issue, #2134 |
Why not put off the decoding step until we are in the api_client and then decode if needed? Python3 Python2 Optionally, in python2 we could also use the python2 backport of the python3 bytes class from the future library: https://python-future.org/what_else.html#bytes though I think that returning instances of that class may confuse people. My preference would be to use the backport class, as it unifies how the type behaves in python2 and python3. |
This issue has been resolved by #5679 |
Thanks @CrshOverride |
In rest.py if PY3 is used and _preload_content is True, the response content is always decoded as utf8. This doesn't make sense for non-text files, e.g. an api that returns a file.
openapi-generator/modules/openapi-generator/src/main/resources/python/rest.mustache
Line 213 in b594262
I welcome any suggestion on how to tackle this but the two solution that come to mind are:
A simple example would be something like
Where obviously the list of Content-Types to "skip" would be a meaningful one and not only octet-stream.
Happy to work on this when I have some confirmation the problem is here / feedback on the right approach.
The text was updated successfully, but these errors were encountered: