python - 使用 connexion+Flask+Swagger 时出现 python 微服务错误

标签 python connexion

我正在尝试使用 python 制作微服务,我正在关注 this tutorial

但我收到此错误:

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

项目结构:

project structure image

App.py文件代码

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文件代码

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文件代码

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


def search() -> list:
    return items

最佳答案

好的...我能够解决这个问题...问题出在app.py中,您必须指定变量端口:

不正确

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

正确

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

关于python - 使用 connexion+Flask+Swagger 时出现 python 微服务错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54267286/

相关文章:

python - 为什么 scipy.special.hankel1(0, 10**10) 返回 `nan` ?

python - 在 PyMongo 中使用 IS NULL

python - 如何从 eBay Trading API 获取品牌名称?

Python 连接不显示 Swagger UI

python - 在 swagger python 服务器 stub 处将 token 授权装饰器添加到端点的任何解决方法

python - 尝试绘制简单柱形图时遇到 "TypeError: integer argument expected, got float"

python - Robot 的 Telnet 库是如何工作的?

python-3.x - 连接:无法在模块中找到 Flask 应用程序或工厂

python - 在 connexion/flask 应用程序中,如何伪造端点正文中带有参数的发布请求?

python - 连接中的 ModuleNotFoundError