zoukankan      html  css  js  c++  java
  • Error generating Swagger server (Python Flask) from Swagger editor

    http://stackoverflow.com/questions/36416679/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. 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. 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
    share|improve this question
     
    1                                                                                  
    Please open a ticket via github.com/swagger-api/swagger-codegen/issues for tracking.                     – wing328                 Apr 6 at 4:45                                                                            

    1 Answer                                 1

             up vote3down voteaccepted

    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). If you create those 2 empty files after generating the code, things should work. 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.

  • 相关阅读:
    贝塞尔曲线原理(转载)
    无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll
    HDU 3530 Subsequence(单调队列)
    Gym 100247I Meteor Flow(优先队列)
    BZOJ 1040: [ZJOI2008]骑士(基环树dp)
    Gym 100247C Victor's Research(有多少区间之和为S)
    Gym 100247A The Power of the Dark Side
    Gym 100247B Similar Strings(哈希+思维)
    51nod 1405 树的距离之和(dfs)
    51nod 1378 夹克老爷的愤怒(树型dp+贪心)
  • 原文地址:https://www.cnblogs.com/kungfupanda/p/5522137.html
Copyright © 2011-2022 走看看