我正在学习一个教程: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
答案 0 :(得分:1)
在您的virtualenv中,执行;
Transformer
以上内容将纠正您的错误,pip install connexion[swagger-ui]
位于产生的错误的顶部。
我遇到了类似的问题。在安装了额外的连接(上面)之后,它解决了我遇到的其他错误。
我在bitshares-explorer-api的自述文件中找到了这个