Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2623
Closed
Open
Issue created Apr 08, 2019 by Administrator@rootContributor6 of 6 checklist items completed6/6 checklist items

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

Created by: 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())
Assignee
Assign to
Time tracking