从Swagger编辑器生成Swagger服务器(Python Flask)时出错

时间:2016-04-05 03:36:14

标签: python flask swagger

我使用Swagger编辑器手动生成Swagger规范文件并为Python Flask服务器生成文件。在README之后我安装了connexion,但是当我运行python app.py时,我收到错误: ValueError:需要多于1个值才能解压缩。有什么想法吗?

下面的完整堆栈跟踪:

No handlers could be found for logger "connexion.api"
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    app.add_api('swagger.yaml')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/app.py", line 144, in add_api
    debug=self.debug)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 127, in __init__
    self.add_paths()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 198, in add_paths
    six.reraise(*sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 187, in add_paths
    self.add_operation(method, path, endpoint, path_parameters)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 160, in add_operation
    resolver=self.resolver)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/operation.py", line 168, in __init__
    resolution = resolver.resolve(self)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/resolver.py", line 50, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/resolver.py", line 71, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/utils.py", line 106, in get_function_from_name
    module_name, attr_path1 = module_name.rsplit('.', 1)
ValueError: need more than 1 value to unpack

1 个答案:

答案 0 :(得分:4)

我也碰到了这个。从我看来,Swagger生成的代码似乎假设您使用的是Python 3.而connexion同时支持Python 2.7和&amp; 3.4+,它确实需要在生成的__init__.py基目录中的python-flask-server/文件以及controllers/子目录中的文件,以便为Python 2.7工作(Python 3.3中引入了隐式命名空间包)。如果在生成代码后创建这两个空文件,则应该可以正常工作。如果Swagger生成器想要支持Python 2.7(因为connexion允许它),它只需要提供这些文件。