首页 > 解决方案 > 在 Flask API (windows) 中创建批处理文件以执行 POST 方法

问题描述

我必须创建一个批处理文件,以便它调用以下 API POST 方法并在 Windows 上无缝执行它。此处不需要向 POST 方法提供任何输入

这适用于 API 调用的 ML 模块。我尝试通过批处理文件和 anaconda 提示符直接调用提到的模块,但这不能正常工作。

import CLassName1
from flask import Flask

app=Flask(__name__)

@app.route('/api/model/testing', methods=['POST'])
def test_model():
     response=ClassName1.method_name1()
     return response

@app.route('/test')
def post_health():
     return "health"

if __name__ == '__main__':
     app.run(host='127.0.0.1',port=15010, debug=True)

预计将运行 method_name1 和后续方法,然后填充在父文件夹中创建的另一个文件-“输出”。

实际上-当直接从anaconda提示执行method_name1时会在一段时间后引发导入错误并不断循环

标签: python-3.xrestapiflask

解决方案


您能否分享您在调用 method_name1() 时得到的确切错误堆栈跟踪,因为只要 method_name1() 返回字符串或 method_name1() 中没有错误,此代码就应该运行。


推荐阅读