我正在使用烧瓶和连接子来设置我的应用程序的REST访问权限。
场景1:--如果我通过Pycharm /debug工具启动我的应用程序--一切正常(烧瓶应用程序运行,包括文件中的API )。
场景2:,但通过终端执行python agreement_api/app.py (包含app实例的主脚本)给我在将specification.yaml API绑定到烧瓶应用程序时出错:
AttributeError: module 'agreement_api.controllers.agreement_controller' has no attribute 'read_agreements'很明显,上面的错误消息告诉我,方法"read_agreeements“并不存在,但请相信我,它确实存在(因为场景1工作正常,没有排字,等等)我的目录结构如下:
- models
- openapi
- specification.yaml - app.py- Dockerfile
- Pipfile
- License
- ...agreement_controller.py
....
def read_agreements():
agreements = Agreement.query.order_by(Agreement.agreement_status).all()
agreement_schema = AgreementSchema(many=True)
return agreement_schema.dump(agreements), 200
....specification.yaml
servers:
- url: /api
paths:
/agreement:
get:
tags:
- Agreement
summary: Read the list of agreements
description: Read the list of agreements
x-openapi-router-controller: agreement_api.controllers.agreement_controller
operationId: read_agreementsapp.py
# Get the application instance
_, connexion_app = create_app()
app = connexion_app.app # Flask instance initialized by Connexion
DB = SQLAlchemy(app)
DB.create_all()
MA = Marshmallow(app)
connexion_app.add_api("specification.yaml")(在Docker容器中运行烧瓶应用程序时也会遇到同样的问题。)
我的目录结构有问题吗?还是我遗漏了其他的东西?我以前没有发过多少问题(应该是我糟糕的阐述/解释/风格所能看到的,所以如果需要的话,可以随意问我任何细节)。
如果有人对错误堆栈跟踪感兴趣:
Failed to add operation for GET /api/agreement
Failed to add operation for GET /api/agreement
Traceback (most recent call last):
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 209, in add_paths
self.add_operation(path, method)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 173, in add_operation
pass_context_arg_name=self.pass_context_arg_name
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/operations/__init__.py", line 8, in make_operation
return spec.operation_cls.from_spec(spec, *args, **kwargs)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/operations/openapi.py", line 138, in from_spec
**kwargs
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/operations/openapi.py", line 89, in __init__
pass_context_arg_name=pass_context_arg_name
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/operations/abstract.py", line 96, in __init__
self._resolution = resolver.resolve(self)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/resolver.py", line 40, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/resolver.py", line 66, in resolve_function_from_operation_id
raise ResolverError(str(e), sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: module 'agreement_api.controllers.agreement_controller' has no attribute 'read_agreements'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "agreement_api/app.py", line 62, in <module>
validator_map={"body": RequestBodyValidator},
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 57, in add_api
api = super(FlaskApp, self).add_api(specification, **kwargs)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apps/abstract.py", line 156, in add_api
options=api_options.as_dict())
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 111, in __init__
self.add_paths()
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 216, in add_paths
self._handle_add_operation_error(path, method, err.exc_info)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
raise value.with_traceback(traceback)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
return self.function_resolver(operation_id)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/utils.py", line 111, in get_function_from_name
module = importlib.import_module(module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abdullah/Documents/projects/mine/user_agreement_flask_api/agreement_api/controllers/agreement_controller.py", line 3, in <module>
from agreement_api.app import DB
File "/home/abdullah/Documents/projects/mine/user_agreement_flask_api/agreement_api/app.py", line 62, in <module>
validator_map={"body": RequestBodyValidator},
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 57, in add_api
api = super(FlaskApp, self).add_api(specification, **kwargs)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apps/abstract.py", line 156, in add_api
options=api_options.as_dict())
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 111, in __init__
self.add_paths()
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 216, in add_paths
self._handle_add_operation_error(path, method, err.exc_info)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
raise value.with_traceback(traceback)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
return self.function_resolver(operation_id)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/utils.py", line 120, in get_function_from_name
function = deep_getattr(module, attr_path)
File "/home/abdullah/.local/share/virtualenvs/user_agreement_flask_api-7tGsycJK/lib/python3.6/site-packages/connexion/utils.py", line 68, in deep_getattr
return functools.reduce(getattr, attrs, obj)
AttributeError: module 'agreement_api.controllers.agreement_controller' has no attribute 'read_agreements'发布于 2020-08-05 17:04:42
https://stackoverflow.com/questions/63250035
复制相似问题