2016-04-05 94 views
2

我已經使用了Swagger編輯器來手動生成Swagger規範文件並生成了Python Flask服務器的文件。在README之後我安裝了connexion,但是當我運行python app.py時出現錯誤: ValueError:需要多個值才能解包。有任何想法嗎?從Swagger編輯器生成Swagger服務器(Python Flask)時出錯

完整的堆棧跟蹤如下:

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

請通過https://github.com/swagger-api/swagger-codegen/issues打開一張票以進行跟蹤。 –

回答

4

我碰到了這一點。從我看到的,Swagger生成的代碼似乎假定您正在使用Python 3.雖然connexion同時支持Python 2.7 & 3.4+,但它在生成的python-flask-server/基目錄以及controllers/子目錄內需要一個__init__.py文件爲Python 2.7工作(隱式命名空間包在Python 3.3中引入)。如果你在生成代碼後創建這兩個空文件,事情應該可以工作。如果Swagger生成器想要支持Python 2.7(因爲connexion允許),它只需要提供這些文件。

+0

解決了這個問題,但遇到了其他問題: def some_function(p1,p2) - > str:default_controller.py中的語法無效。 @letsgoblue你有沒有得到這與Python 2.7的工作? – tw1742

+1

@ tw1742:啊,是的,也改變了 - 在Python 3.5+中新增了類型提示,所以爲了兼容Python 2.7,只需刪除該文件中的' - > str'&類似部分,就可以全部設置。 – letsgoblue

+0

好的,該應用程序正在運行,但沒有顯示任何內容,並且它返回了404。 – tw1742

相關問題