Python 3.x 由于';没有名为';错误

Python 3.x 由于';没有名为';错误,python-3.x,yaml,swagger,pypi,connexion,Python 3.x,Yaml,Swagger,Pypi,Connexion,我正在使用OpenAPI 3.0.1 yaml,由于以下错误,它无法启动API Web服务器。我尝试了我所知道的几乎所有东西,但我对OpenAPI非常陌生,文档也照样做了。你有没有想过这里会出什么问题 这是加载服务器时出现的错误: Failed to add operation for GET /v2/catalog Traceback (most recent call last): File "C:\Programs\Python\Python38\lib\site-packa

我正在使用OpenAPI 3.0.1 yaml,由于以下错误,它无法启动API Web服务器。我尝试了我所知道的几乎所有东西,但我对OpenAPI非常陌生,文档也照样做了。你有没有想过这里会出什么问题

这是加载服务器时出现的错误:

Failed to add operation for GET /v2/catalog
Traceback (most recent call last):
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apis\abstract.py", line 209, in add_paths
    self.add_operation(path, method)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apis\abstract.py", line 162, in add_operation
    operation = make_operation(
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\operations\__init__.py", line 8, in make_operation
    return spec.operation_cls.from_spec(spec, *args, **kwargs)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\operations\openapi.py", line 128, in from_spec
    return cls(
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\operations\openapi.py", line 75, in __init__
    super(OpenAPIOperation, self).__init__(
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\operations\abstract.py", line 96, in __init__
    self._resolution = resolver.resolve(self)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\resolver.py", line 40, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\resolver.py", line 64, in resolve_function_from_operation_id
    raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "catalog.get"! Import error was "No module named 'catalog'">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\API\swagger_server\__main__.py", line 25, in <module>
    main()
  File "D:\API\swagger_server\__main__.py", line 18, in main
    app.add_api('D:\API\swagger_server\swagger\swagger.yaml', arguments={'title': 'GPI API Broker'}, pythonic_params=True)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apps\flask_app.py", line 57, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apps\abstract.py", line 141, in add_api
    api = self.api_cls(specification,
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apis\abstract.py", line 111, in __init__
    self.add_paths()
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apis\abstract.py", line 216, in add_paths
    self._handle_add_operation_error(path, method, err.exc_info)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\apis\abstract.py", line 231, in _handle_add_operation_error
    raise value.with_traceback(traceback)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\resolver.py", line 61, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "C:\Programs\Python\Python38\lib\site-packages\connexion\utils.py", line 110, in get_function_from_name
    module = importlib.import_module(module_name)
  File "C:\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'catalog'

提前谢谢大家

操作ID必须与应用程序的运行位置相关

swagger_server
|-- app.py
|-- __init__.py
|-- OpenAPI
|   |-- openapi.yml
|-- models
|   |-- catalog.py
根据上述文件夹结构,您可以在目录swagger_服务器中启动应用程序。因此,
app.py
的路径在您的
sys.path
中。相对于此路径,您需要在
openapi.yml
中指定
操作ID

paths:
  /v2/catalog:
    get:
      tags:
      - Catalog
      summary: get the catalog of services that the service broker offers
      operationId: 'models.catalog.get'

文件catalog.py必须包含函数
def get(name)
。在这里,您可以定义端点的服务/处理程序。它必须包含参数
name
,因为您已在YAML文件中指定了该参数。

operationId:“catalog.get”
在Python术语中是指来自catalog import get的
。您是否有模块或软件包
目录
,可以从中导入name
get
?是的。在我的D:\API\swagger\u server\models中,我有一些模块,其中一个是catalog.py:#编码:utf-8从future导入绝对值#从datetime导入日期#datetime#noqa:F401从键入导入列表,Dict#noqa:F401从swagger\u server.models.base\u model#从swagger\u server.models.service导入服务#noqa:F401,E501来自swagger_服务器导入util类目录(型号):“”“注意:这个类是由swagger代码生成器程序自动生成的…”。。。operationId必须与您运行应用程序的位置相关。例如,如果您的应用程序在目录swagger_服务器中运行,则需要在yml中指定“models.catalog.get”。谢谢,@高于\u c_级别。这可以解决这个问题。我现在有另一个问题:“AttributeError:module'models.catalog'没有属性'get'”,但我相信这是由swagger生成的代码出了问题,好像YAML指定了它,模块应该有get属性,对吗?也许'get'只是一个默认值。我认为Connexion定义了这样的默认值。但是,您只需打开catalog.py并查看是否有函数get()。如果没有,你必须写一个。:)
paths:
  /v2/catalog:
    get:
      tags:
      - Catalog
      summary: get the catalog of services that the service broker offers
      operationId: 'models.catalog.get'