IBM Watson Personality Insights Service:给出错误的请求作为响应

问题描述 投票:2回答:1

我正在使用watson的NodeJS SDK来测试Personality Insights Service,但收到以下错误:

> Error: { Bad Request: Invalid JSON input at line 1, column 2
>     at RequestWrapper.formatError (C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:208:21)
>     at C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:196:25
>     at process._tickCallback (internal/process/next_tick.js:109:7)   name: 'Bad Request',   code: 400,   message: 'Invalid JSON input at
> line 1, column 2',   body:
> '{"code":400,"sub_code":"S00005","error":"Invalid JSON input at line
> 1, column 2"}',   headers:    { 'content-type': 'application/json',
>      'content-length': '81',
>      'access-control-allow-origin': '*',
>      'x-service-api-version': '4.0.2',
>      'x-service-build-number': '2020-01-20T06:02:53.029 UTC',
>      'x-content-type-options': 'nosniff',
>      'x-xss-protection': '1; mode=block',
>      'content-security-policy': 'default-src \'none\'',
>      pragma: 'no-cache',
>      'cache-control': 'no-store',
>      'x-service-pi-error-code': 'S00005',
>      'content-language': 'en-US',
>      'strict-transport-security': 'max-age=31536000; includeSubDomains;',
>      'x-global-transaction-id': '833a39d917c511e8921aa5286669721c',
>      'x-dp-watson-tran-id': '833a39d917c511e8921aa5286669721c',
>      'x-edgeconnect-midmile-rtt': '289',
>      'x-edgeconnect-origin-mex-latency': '416',
>      date: 'Tue, 28 Jan 2020 02:59:53 GMT',
>      connection: 'close' } }

下面是我正在使用的代码片段:

app.get("/personality-insights", function(req, res) {

    const personalityInsights = new PersonalityInsightsV3({
    version: '2017-10-13',
    authenticator: new IamAuthenticator({
      apikey: watsonKeyPersonalityInsights,
    }),
    url: watsonUrlPersonalityInsights,
  });

  let params = {
    content: "I am very happy today",
    content_type: 'text/plain',
    raw_scores: true,
    consumption_preferences: true
  };

    personalityInsights.profile(params, function(error, response) {
    if (error)
      console.log('Error:', error);
    else
      console.log(JSON.stringify(response, null, 2));
    }
  );

});

这是一个基于Node JS的示例代码片段,我在其中提供API凭证和IBM云提供的URL,并使用单行输入文本进行请求。一切似乎都是正确的,但不知道为什么我会收到该错误。

node.js json ibm-watson personality-insights
1个回答
2
投票
contentType

rawScores

© www.soinside.com 2019 - 2024. All rights reserved.