【问题标题】:Azure Machine Learning REST API: no bodyAzure 机器学习 REST API:没有正文
【发布时间】:2017-09-25 14:18:04
【问题描述】:

我只是尝试调用使用 Azure 创建的机器学习实验的 REST API 端点。我不断收到此错误消息:

{
    "error": {
        "code": "BadArgument",
        "message": "Invalid argument provided.",
        "details": [
            {
                "code": "RequestBodyInvalid",
                "message": "No request body provided or error in deserializing the request body."
            }
        ]
    }
}

我已经在他们的文档中查找过:https://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-web-service-error-codes

它只是说我的身体是空的,我不确定它怎么会是空的,这是我的代码:

router.post('/rating/new', function(req, res) {
    var postData = {
        "Inputs": {
            "input2":
                [
                    {
                        'Col1': "A11",
                        'Col2': "6",
                        'Col3': "A34",
                        'Col4': "A43",
                        'Col5': "1169",
                        'Col6': "A65",
                        'Col7': "A75",
                        'Col8': "4",
                        'Col9': "A93",
                        'Col10': "A101",
                        'Col11': "4",
                        'Col12': "A121",
                        'Col13': "67",
                        'Col14': "A143",
                        'Col15': "A152",
                        'Col16': "2",
                        'Col17': "A173",
                        'Col18': "1",
                        'Col19': "A192",
                        'Col20': "A201",
                        'Col21': "1",
                    }
                ],
        },
        "GlobalParameters":  {
        }
    };

    // Configure the request
    var options = {
        url: config.ML_PREDICTIVE.url,
        method: 'POST',
        headers: {
            'Content-Type':'application/json',
            'Authorization':('Bearer ' + config.ML_PREDICTIVE.apiKey)},
        form: postData
    }

    console.log(JSON.stringify(options));

    // Start the request
    request.post(options, function (error, response, body) {
        if(error){
            res.status(403).send(error);
        }
        if(response.statusCode != 200){
            res.status(403).send(response.body);
        }
        if (!error && response.statusCode == 200) {
            console.log(body)
        }
    })
});

我看到唯一可能出错的是请求中的“表单”不被 azure 视为正文,我尝试使用“正文”也没有成功。

请帮忙!

【问题讨论】:

    标签: rest azure machine-learning


    【解决方案1】:

    根据您提供的代码,变量 postData 不是有效的 JSON 字符串。在发送 POST 请求之前,您需要使用 JSON.stringify() 方法将 postData 值转换为 JSON 字符串。

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2023-02-26
      • 2019-01-03
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2020-01-30
      • 1970-01-01
      相关资源
      最近更新 更多