Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在模块“中找不到烧瓶应用程序或工厂”;“运行”;_Python_Flask_Swagger_Connexion - Fatal编程技术网

Python 在模块“中找不到烧瓶应用程序或工厂”;“运行”;

Python 在模块“中找不到烧瓶应用程序或工厂”;“运行”;,python,flask,swagger,connexion,Python,Flask,Swagger,Connexion,我正在尝试运行一个简单的connexion REST-API。我已经在run.py上实例化了connexion的实例 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 hom

我正在尝试运行一个简单的connexion REST-API。我已经在
run.py
上实例化了connexion的实例

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规范
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"
应用程序的用户详细信息<代码>用户.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())]
对于延迟启动,我创建了shell文件
server.sh

export FLASK_APP=run.py
export FLASK_DEBUG=1

flask run
应用程序的文件夹结构

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
当我运行shell时,它会给出以下错误

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

这里可能有什么问题?

您的swagger文件中映射了
@app.route(“/”)
?我想这是行不通的。即使我把它去掉,它似乎也不起作用。使用
PYTHONPATH=”执行时也会出现同样的错误。烧瓶运行
?您也可以尝试使用
connexion run执行