我正在尝试使用 python 制作微服务,我正在关注 this tutorial
但我收到此错误:
"flask_app.py", line 115, in run
raise Exception('Server {} not recognized'.format(self.server))
Exception: Server 9090 not recognized
项目结构:
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/