2

我正在使用 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,并使用单行输入文本发出请求。一切似乎都是正确的,但不知道为什么我会收到这个错误。

4

1 回答 1

3

在 v5.1 中,所有参数都转换为小驼峰式大小写。请参阅 repo 中的MIGRATION文档和API 参考中的参数详细信息

  • contentType
  • rawScores
  • consumptionPreferences
于 2020-01-28T14:00:44.280 回答