我试着用python做一个微服务,我在跟踪本教程
但我发现了一个错误:
"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发布于 2019-01-19 14:58:00
好的..。我解决了这个问题..。问题在app.py中,您必须指定变量端口:
不正确
app = connexion.App(__name__, 9090, specification_dir='swagger/')对,是这样
app = connexion.App(__name__, port=9090, specification_dir='swagger/')发布于 2019-02-09 16:29:35
Python中有大量的微服务框架,可以大大简化您必须编写的代码。
例如,请尝试使用pymacaron (http://pymacaron.com/)。下面是用pymacaron实现的helloworld的一个示例:https://github.com/pymacaron/pymacaron-helloworld
pymacaron服务只要求您:(1)为您的api编写一个傲慢的规范(无论您使用哪种语言,它总是一个很好的起点)。swagger文件描述api的get/post/etc调用以及它们获取和返回的对象(json ),以及实现端点的代码中的哪个python方法。(2)并实现端点的方法。
一旦您这样做了,您就可以免费获得大量的东西:您可以将代码打包为一个停靠容器,将其部署到AmazonBean秸秆,从api调用中启动异步任务,或者不需要额外的工作就可以获得api文档。
https://stackoverflow.com/questions/54267286
复制相似问题