Bug Report Checklist
Description
The multipart mixed post fails when trying to send objects.
openapi-generator version
7.4.0
OpenAPI declaration file content or url
form-multipart-binary-array.yaml
Generation Details
java -jar openapi-generator-cli.jar generate -i form-multipart-binary-array.yaml -g python -o test-client
Steps to reproduce
Generate client with mentioned YAML spec and try to run the client like:
with openapi_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = openapi_client.MultipartApi(api_client)
marker = MultipartMixedRequestMarker(name="Test")
try:
api_instance.multipart_mixed(
status=MultipartMixedStatus.ALLOWED, file="<file>", marker=marker
)
except Exception as e:
print("Exception when calling MultipartApi->multipart_array: %s\n" % e)
Suggest a fix
The exception actually occurs in urllib3 when, it tries to write the object into a byte stream and can't interpret the dict as bytes (body.write(data)):
def encode_multipart_formdata(
fields: _TYPE_FIELDS, boundary: str | None = None
) -> tuple[bytes, str]:
"""
Encode a dictionary of ``fields`` using the multipart/form-data MIME format.
:param fields:
Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`).
Values are processed by :func:`urllib3.fields.RequestField.from_tuples`.
:param boundary:
If not specified, then a random boundary will be generated using
:func:`urllib3.filepost.choose_boundary`.
"""
body = BytesIO()
if boundary is None:
boundary = choose_boundary()
for field in iter_field_objects(fields):
body.write(f"--{boundary}\r\n".encode("latin-1"))
writer(body).write(field.render_headers())
data = field.data
if isinstance(data, int):
data = str(data) # Backwards compatibility
if isinstance(data, str):
writer(body).write(data)
else:
body.write(data)
body.write(b"\r\n")
Error message: a bytes-like object is required, not 'dict'
Bug Report Checklist
Description
The multipart mixed post fails when trying to send objects.
openapi-generator version
7.4.0
OpenAPI declaration file content or url
form-multipart-binary-array.yaml
Generation Details
java -jar openapi-generator-cli.jar generate -i form-multipart-binary-array.yaml -g python -o test-clientSteps to reproduce
Generate client with mentioned YAML spec and try to run the client like:
Suggest a fix
The exception actually occurs in
urllib3when, it tries to write the object into a byte stream and can't interpret thedictas bytes (body.write(data)):Error message:
a bytes-like object is required, not 'dict'