0

I'm trying to run a simple connexion REST-API. I have instantiated the instance of connexion on run.py.

import os
import connexion
from flask import render_template
from users import read

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

@app.route('/')
def home():
    return 'Welcome to users API'

if __name__ == 'main':
    app.run(port='5000', host='0.0.0.0', debug=True)

Swagger specification for the server swagger.yaml

swagger: "2.0"
info:
  description: Auth users details
  version: "1.0.0"
  title: Swagger specification for the Auth contracts
consumes:
  - "application/json"
produces:
  - "application/json"

basePath: "/api"

paths:
  /users:
    get:
      operationId: "users.read"
      tags:
        - "Users"
      summary: "The users data structure supported by the server application"
      description: "Read the list of users"
      responses:
        200:
          description: "Successful read users list operation"
          schema:
            type: "array"
            items:
              properties:
                fname:
                  type: "string"
                lname:
                  type: "string"
                timestamp:
                  type: "string"

User details of the application. users.py

from datetime import datetime

def get_timestamp():
    return datetime.now().strftime(("%Y-%m-%d %H:%M:%S"))


users = {
    'Tom': {
        'fname': 'Tom',
        'lname': 'Riddle',
        'timestamp': get_timestamp()
    },
    'Harry': {
        'fname': 'Harry',
        'lname': 'Potter',
        'timestamp': get_timestamp()
    },
    'Dumbledore': {
        'fname': 'Brian',
        'lname': 'Dumbledore',
        'timestamp': get_timestamp()
    },
}

def read():
    return [users[key] for key in sorted(users.keys())]

For lazy launching I have created the shell file server.sh

export FLASK_APP=run.py
export FLASK_DEBUG=1

flask run

Folder structure for the application.

W/D
├── __pycache__
│   ├── __init__.cpython-37.pyc
│   ├── people.cpython-37.pyc
│   ├── run.cpython-37.pyc
│   └── users.cpython-37.pyc
├── run.py
├── server.sh
├── swagger.yaml
└── users.py

When I run the shell it gives this error..

flask.cli.NoAppException: Failed to find Flask application or factory in module "run". Use "FLASK_APP=run:name to specify one.

What could be the issue here?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Govinda Malavipathirana
  • 1,095
  • 2
  • 11
  • 29

0 Answers0