简体   繁体   English

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

[英]Error generating Swagger server (Python Flask) from Swagger editor

I've used the Swagger Editor to manually generate my Swagger spec file and generated the files for a Python Flask server. 我已经使用Swagger编辑器手动生成了Swagger规范文件,并为Python Flask服务器生成了文件。 Following the README I installed connexion, but when I run python app.py I get the error: ValueError: need more than 1 value to unpack. 按照自述文件,我安装了connexion,但是当我运行python app.py出现错误:ValueError:需要多个值才能解压。 Any ideas? 有任何想法吗?

Full stack trace below: 完整的堆栈跟踪如下:

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

I ran into this as well. 我也遇到了这个问题。 From what I see, the generated code from Swagger seems to assume you're using Python 3. While connexion supports both Python 2.7 & 3.4+, it does need a __init__.py file in the generated python-flask-server/ base directory as well as inside the controllers/ subdirectory to work for Python 2.7 (Implicit Namespace Packages were introduced in Python 3.3). 从我看来,从Swagger生成的代码似乎假设您正在使用Python3。尽管connexion支持Python 2.7和3.4+,但确实需要在生成的python-flask-server/基本目录中有一个__init__.py文件,如下所示:以及在controllers/子目录中以适用于Python 2.7(隐式命名空间包是在Python 3.3中引入的)。 If you create those 2 empty files after generating the code, things should work. 如果在生成代码后创建了这2个空文件,则一切正常。 If the Swagger generator wants to support Python 2.7 (since connexion allows for it), it would just need to provide those files as well. 如果Swagger生成器想要支持Python 2.7(因为connexion允许它),则只需提供这些文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM