gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:37:35 24 4
gpt4 key购买 nike

我已使用 Swagger 编辑器手动生成我的 Swagger 规范文件并为 Python Flask 服务器生成文件。按照自述文件,我安装了 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

最佳答案

我也遇到过这个问题。据我所知,Swagger 生成的代码似乎假设您使用的是 Python 3。虽然 connexion 支持 Python 2.7 和 3.4+,但它在生成的 中确实需要一个 __init__.py 文件>python-flask-server/ 基本目录以及 controllers/ 子目录中,以用于 Python 2.7(Python 3.3 中引入了隐式命名空间包)。如果您在生成代码后创建这 2 个空文件,应该可以正常工作。如果 Swagger 生成器想要支持 Python 2.7(因为 connexion 允许),它也只需要提供这些文件。

关于python - 从 Swagger 编辑器生成 Swagger 服务器(Python Flask)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36416679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com