A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/swagger-api/swagger-codegen/issues/10948 below:

[Python] response.data has type "str" but file opened with "wb" mode, need be "w" · Issue #10948 · swagger-api/swagger-codegen · GitHub

Description Swagger-codegen version

3.0.25

Swagger declaration file content or url
swagger: '2.0'
info:
  title: Some API
  description: Some API
  version: "1.0.0"
schemes:
  - http
produces:
  - application/json
paths:
  /export:
    get:
      operationId: export_op
      x-swagger-router-controller: source
      summary: Some export
      tags:
        - Sources
      responses:
        200:
          description: done
          schema:
            type: file
Command line used for generation
docker run --rm \
    -v $(pwd)/some.yml:/some.yml \
    -v $(pwd)/result:/tmp/result \
    swaggerapi/swagger-codegen-cli-v3:3.0.25 \
    generate -i /some.yml -l python -o /tmp/result
Steps to reproduce

Just execute command

Suggest a fix/enhancement

I'll try fix this

BUG

in result/swagger_client/api_client.py file
in __deserialize_file method:

def __deserialize_file(self, response):
        """Deserializes body to file

        Saves response body into a file in a temporary folder,
        using the filename from the `Content-Disposition` header if provided.

        :param response:  RESTResponse.
        :return: file path.
        """
        fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
        os.close(fd)
        os.remove(path)

        content_disposition = response.getheader("Content-Disposition")
        if content_disposition:
            filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
                                 content_disposition).group(1)
            path = os.path.join(os.path.dirname(path), filename)
        
        with open(path, "wb") as f:
            f.write(response.data)

        return path

Error in block with writing to file
response.data has type "str" but file opened with "wb" mode, need be "w"


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4