-
-
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
[BUG] [PYTHON] Python client decodes file to string and fails to write bytes #4847
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
For file types, this has been fixed by #5679 |
I have the same problem |
@thall please provide a spec, headers, body content and what generator you are using, and your error message so your issue can be reproduced |
@spacether /odd/{uuid}/tile/{tile_id}:
get:
tags:
- ODD
summary: Get tile from ODD layer with UUID by ID
description: Get tile belonging to ODD layer with `uuid` by `tile_id`
parameters:
- $ref: '#/components/parameters/uuid'
- $ref: '#/components/parameters/tile_id'
responses:
200:
$ref: '#/components/responses/tile_object'
...
tile_object:
description: Tile with map objects, serialized to binary format
content:
application/octet-stream:
schema:
type: string
format: binary Client generated with: docker run --rm -v "${PWD}:/local" --workdir /local --user ${UID}:${GROUPS[0]}
openapitools/openapi-generator-cli generate
--config openapi-generator-config.yaml
--input-spec openapi.yaml
--generator-name python
--output integration-test Error message: ...
File "/home/s0000625/code/madmap_compiler/.venv/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/api/odd_api.py", line 224, in __odd_uuid_tile_tile_id_get
return self.call_with_http_info(**kwargs)
File "/home/s0000625/code/madmap_compiler/.venv/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/api_client.py", line 826, in call_with_http_info
return self.api_client.call_api(
File "/home/s0000625/code/madmap_compiler/.venv/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/api_client.py", line 406, in call_api
return self.__call_api(resource_path, method,
File "/home/s0000625/code/madmap_compiler/.venv/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/api_client.py", line 220, in __call_api
response_data.data = response_data.data.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 7: invalid continuation byte Data returned by server:
|
Thank you for providing that info! Is there a url that I can hit to get the response headers? Or could you provide them? |
Its not a public endpoint, but i can provide curl output:
Is that enough? |
Awesome, thanks! Yes it is. I can use that to write a test and fix it. |
This should be fixed by the above merge |
Can confirm that the patch fixes the problem. Thanks @spacether! |
Bug Report Checklist
Description
Generating a python client (experimental and normal) and using said client in python3 breaks when downloading a file. This works in python2!
I'm using
application/octet-stream
withtype: string
andformat: binary
(see below).openapi-generator version
4.2.2
OpenAPI declaration file content or url
Gist available at https://gist.github.com/vmorris/8593cdf7d96451f6ccdc994b2953ffcb
Add this snippet to the petshop documentation:
Command line used for generation
openapi-generator-cli generate -i petshop.yaml -g python -o petshop_client
Steps to reproduce
This gets down into
openapi_client/api_client.py:__deserialize_file(self, response)
, where the temporary output file is opened as 'wb'. This works fine if using python 2, but in python 3, it fails withTypeError: a bytes-like object is required, not 'str'
I was able to work around this by adding
_preload_content=False
to the API call and then writing the data out to a file myself.Related issues/PRs
#206
Suggest a fix
Perhaps don't
decode
response.data to a string when format is binary.The text was updated successfully, but these errors were encountered: