我正在学习一个教程:https ://medium.com/@ssola/building-microservices-with-python-part-i-5240a8dcc2fb
from connexion.resolver import RestyResolver
import connexion
items = {
0: {"name": "First item"}
}
def search():
return items
if __name__ == '__main__':
app = connexion.App(__name__, 9090, specification_dir='swagger/')
app.add_api('my_super_app.yaml', resolver=RestyResolver('api'))
app.run()
我一直收到同样的错误:ImportError: No module named items
有人知道如何解决这个错误吗?我 pip 安装了所有依赖项
这是 api.itmes
items = {
0: {"name": "First item"}
}
def search() -> list:
return items
这是 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 }
产生的错误:
No handlers could be found for logger "connexion.options"
Traceback (most recent call last):
File "/Users/rabiaasif/Documents/GitHub/MibsBackEnd/marble-project/marbles/flask/bff.py", line 15, in <module>
app.add_api('my_super_app.yaml', resolver=RestyResolver('api'))
File "/Library/Python/2.7/site-packages/connexion/apps/flask_app.py", line 54, in add_api
api = super(FlaskApp, self).add_api(specification, **kwargs)
File "/Library/Python/2.7/site-packages/connexion/apps/abstract.py", line 155, in add_api
options=api_options.as_dict())
File "/Library/Python/2.7/site-packages/connexion/apis/abstract.py", line 107, in __init__
self.add_paths()
File "/Library/Python/2.7/site-packages/connexion/apis/abstract.py", line 212, in add_paths
self._handle_add_operation_error(path, method, err.exc_info)
File "/Library/Python/2.7/site-packages/connexion/apis/abstract.py", line 226, in _handle_add_operation_error
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/connexion/resolver.py", line 64, in resolve_function_from_operation_id
return self.function_resolver(operation_id)
File "/Library/Python/2.7/site-packages/connexion/utils.py", line 99, in get_function_from_name
raise last_import_error
ImportError: No module named items