Python-Flask,由Swagger File生成的服务器产生一些魔术!'所有获取方法

发布于 2025-01-25 09:37:01 字数 1016 浏览 4 评论 0原文

我从Swagger编辑器中生成了Python烧瓶服务器API: https://editor.swagger.io/

当我本地运行服务器时方法产生相同的输出:
“做一些魔术!”

我在所有控制器方法中替换了该短语,并重新启动了服务器。但是它仍然会产生愚蠢的输出而不是预期的输出。它来自哪里?

这是复制问题的方法:

  1. 转到 https://editor.swagger。 IO/并使用一种方法创建简单的接口,
  2. 生成服务器代码Python-flask
  3. 在IDE中打开它(我在Windows上使用VS代码),转到控制器,更新您的Methos的返回并运行./swagger_server/ << strong> main .py
  4. 当服务器准备好响应时,请调用该方法(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?
enter image description here

Here is the way to reproduce the problem:

  1. go to https://editor.swagger.io/ and create simple interface with one method
  2. generate server code python-flask
  3. 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
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2025-02-01 09:37:01

好,我想我在这里很快找到了一个解决方案
https://code.visalstudio.com/docs/docs/docs/python/python/tutore-flask-fore-flask
看来我的VS代码iDE的行为不同:

  • 当您运行_ _ _ main _.py(或app.py- for for Blask)时,它会为所有方法生成该愚蠢的消息
  • ,并且它可以工作正确地,当您按照Doco:python -m swagger_server运行它时

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:

  • when you run _ _ main _ _.py (or app.py - default for Flask) directly, it generates that stupid message for ALL methods
  • and it works correctly, when you run it as described in that doco: python -m swagger_server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文