【问题标题】:IBM Watson Personality Insights Service : giving bad request as responseIBM Watson Personality Insights Service:给出错误请求作为响应
【发布时间】:2020-05-13 10:54:37
【问题描述】:

我正在使用 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' } }

下面是我正在使用的代码 sn-p:

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 的示例 sn-p,我在其中提供 API 凭据和 IBM 云提供的 URL,并使用单行输入文本发出请求。一切似乎都是正确的,但不知道为什么我会收到这个错误。

【问题讨论】:

    标签: node.js json ibm-watson personality-insights


    【解决方案1】:

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

    • contentType
    • rawScores
    • consumptionPreferences

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2016-11-21
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多