Skip to content

[BUG][Python] Can't send binary payload using Python3 and Python client #2623

@sarod

Description

@sarod

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

For API accepting binary payload "application/octet-stream" the python client should support sending binary content.

Using python 3 and current python client if I try to send "bytes" as returned by open(zip_file, 'rb').read() in the payload body the client fails with

Reason: Cannot prepare a request message for provided
                             arguments. Please check that your arguments match
                             declared content type.

The python client should send the binary to the end point in such case.

Note that using Python2 and open(image_file, 'r').read() to read the file works because the client assumes it is a string and it let the string go through.

openapi-generator version

Reproduced with 3.3.4 and 4.0.0 compiled from master.

OpenAPI declaration file content or url
openapi: 3.0.0
servers:
  - url: http://127.0.0.1:10081/api/rest
info:
  version: "1.0.0"
  title: Title
  description: Desc
security:
- basicAuth: []
paths:  
  /admin/image-libraries/{name}:
    parameters:
    - name: name
      in: path
      description: Image library name
      required: true
      schema:
        type: string
    put:
      operationId: importImageLibrary
      summary: Import image library      
      requestBody:
        description: Image library contents (zip)
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: zip
      responses:
        '200':
          description: OK       
Command line used for generation

generate -g python --skip-validate-spec -o .python_client --additional-properties=packageName=python_client,projectName=python_client

Steps to reproduce

Generate the module then execute the following python script

from python_client import ApiClient, Configuration, DefaultApi


config = Configuration()
config.username = 'admin'
config.password = 'admin'

api = DefaultApi(ApiClient(config))

with open('zip.zip', 'rb') as file:
    api.import_image_library(name='imageLib', body=file.read())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions