Python-Flask,由Swagger File生成的服务器产生一些魔术!'所有获取方法
我从Swagger编辑器中生成了Python烧瓶服务器API: https://editor.swagger.io/
当我本地运行服务器时方法产生相同的输出:
“做一些魔术!”
我在所有控制器方法中替换了该短语,并重新启动了服务器。但是它仍然会产生愚蠢的输出而不是预期的输出。它来自哪里?
这是复制问题的方法:
- 转到 https://editor.swagger。 IO/并使用一种方法创建简单的接口,
- 生成服务器代码Python-flask
- 在IDE中打开它(我在Windows上使用VS代码),转到控制器,更新您的Methos的返回并运行./swagger_server/ << strong> main .py
- 当服务器准备好响应时,请调用该方法(http:// localhost:8080/yourmethod),您会注意到它总是返回“做一些魔术!”无论您的控制器包含什么,
def module_health_check(): # noqa: E501
return 'do another magic!'
但是如果您构建Docker并将其作为容器运行,它将按预期正确调用您的控制器。我认为Windows Visual Studio代码中的开发环境设置有问题,这会产生存根会导致运行时间(没有Docker)
I have generated Python Flask-Server API from swagger editor:
https://editor.swagger.io/
When I run the server locally, I noticed that all my get methods produce the same output:
'do some magic!'
I have replaced that phrase in all my controllers methods, and restarted the server. But it still generates that stupid output instead of the expected ones. Where does it come from?
Here is the way to reproduce the problem:
- go to https://editor.swagger.io/ and create simple interface with one method
- generate server code python-flask
- open it in IDE (I am using VS Code on Windows), go to controllers, update return of you methos, and run ./swagger_server/main.py
- when the server is ready to respond, call that method (http://localhost:8080/yourmethod) and you will notice that it always returns 'do some magic!' regardless of what your controller contains
def module_health_check(): # noqa: E501
return 'do another magic!'
But if you build Docker and run it as a container, it will call your controller properly as expected. I think something wrong with my dev environment settings in Windows Visual Studio Code, which generates stub result in run time (without docker)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好,我想我在这里很快找到了一个解决方案
https://code.visalstudio.com/docs/docs/docs/python/python/tutore-flask-fore-flask
看来我的VS代码iDE的行为不同:
Ok, I think I have found a solution shortly described here
https://code.visualstudio.com/docs/python/tutorial-flask
It seems like my VS Code IDE behaves differently: