Forum Discussion

jkulkarni's avatar
jkulkarni
New Contributor
12 months ago
Solved

Swagger UI giving error not enough values to unpack

Hi, I have a simple API with a post endpoint that requires three parameters. When I test it through the python-fask codegen SwaggerUI, I get error saying there are not enough values to unpack.  How to get it to work? Here are the details:

 

From the swagger yaml file:

 
paths:
  /estimate:
    post:
      tags:
      - client_requests
      summary: submits a job by specifying a script file
      operationId: e_post
      requestBody:
        content:
          application_json:
            schema:
              $ref: '#/components/schemas/EJob'
      responses:
        "201":
          description: job_received
        "400":
          description: invalid_input
      callbacks:
        statusUpdate:
          '{$request.body#/callback_url}':
            post:
              requestBody:
                content:
                  application_json:
                    schema:
                      $ref: '#/components/schemas/EJobStatus'
                required: true
              responses:
                "200":
                  description: Accepted by the server
      x-openapi-router-controller: swagger_server.controllers.client_requests_controller

 

and the Ejob Schema from the yaml:

 

 schemas:
    EJob:
      required:
      - callback_url
      - id
      - script_url
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 39
        script_url:
          type: string
          description: A job for backend to execute
          format: uri
          example: file:///data/39_script.json
        callback_url:
          type: string
          description: This URL is called to update status
          format: uri
          example: http:://192.168.100.30:50/update_status

 

The post request from the Swagger UI:

 

curl -X 'POST' \
  'http://localhost:8080/BLA/BLA/1.0.0/estimate' \
  -H 'accept: */*' \
  -H 'Content-Type: application_json' \
  -d '{
  "callback_url": "http:://192.168.100.30:50/update_status",
  "id": 39,
  "script_url": "file:///data/39_script.json"
}'

 

The error I am getting from python-flask codegen generated code:

 

[2023-04-26 17:21:43,069] ERROR in app: Exception on /BLA/BLA/1.0.0/estimate [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.6/site-packages/connexion/decorators/decorator.py", line 68, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.6/site-packages/connexion/decorators/uri_parsing.py", line 149, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.6/site-packages/connexion/decorators/validation.py", line 148, in wrapper
    if all_json(self.consumes):
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 165, in all_json
    return all(is_json_mimetype(mimetype) for mimetype in mimetypes)
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 165, in <genexpr>
    return all(is_json_mimetype(mimetype) for mimetype in mimetypes)
  File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 139, in is_json_mimetype
    maintype, subtype = mimetype.split('/')  # type: str, str
ValueError: not enough values to unpack (expected 2, got 1)
172.17.0.1 - - [26/Apr/2023 17:21:43] "POST /BLA/BLA/1.0.0/estimate HTTP/1.1" 500 -

 

  • The content type should be application/json instead of application_json. The swaggerhub editor should have ideally redlined this.

1 Reply

  • jkulkarni's avatar
    jkulkarni
    New Contributor

    The content type should be application/json instead of application_json. The swaggerhub editor should have ideally redlined this.