Search code examples
pythonconnexion

Error in python microservices with connexion+Flask+Swagger


I'm trying to make a microservice with python, I'm following this tutorial

But I'm getting this error:

"flask_app.py", line 115, in run
    raise Exception('Server {} not recognized'.format(self.server))
Exception: Server 9090 not recognized

Project structure:

project structure image

App.py file code

from connexion.resolver import RestyResolver
import connexion

if __name__ == '__main__':
    app = connexion.App(__name__, 9090, specification_dir='swagger/')
    app.add_api('my_super_app.yaml', resolver=RestyResolver('api'))
    app.run()

my_super_app.yaml file code

swagger: "2.0"

info:
  title: "My first API"
  version: "1.0"

basePath: /v1.0

paths:
  /items/:
    get:
      responses:
        '200':
          description: 'Fetch a list of items'
          schema:
            type: array
            items:
              $ref: '#/definitions/Item'

definitions:
  Item:
    type: object
    properties:
      id:
        type: integer
        format: int64
      name: { type: string }

items.py file code

items = {
    0: {"name": "First item"}
}


def search() -> list:
    return items

Solution

  • ok... i was able to solve this problem... the problem is in app.py, you must specify the variable port:

    INCORRECT

    app = connexion.App(__name__, 9090, specification_dir='swagger/')
    

    CORRECT

    app = connexion.App(__name__, port=9090, specification_dir='swagger/')