IBM Watson Personality Insights Service:给出错误的请求作为响应
IBM Watson Personality Insights Service : giving bad request as response
我正在使用 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 并使用单行输入文本发出请求。一切似乎都是正确的,但不知道为什么会出现该错误。
所有参数在 v5 中都转换为小驼峰大小写。参见 MIGRATION doc in the repo and the parameter details in the API reference
contentType
rawScores
consumptionPreferences
我正在使用 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 并使用单行输入文本发出请求。一切似乎都是正确的,但不知道为什么会出现该错误。
所有参数在 v5 中都转换为小驼峰大小写。参见 MIGRATION doc in the repo and the parameter details in the API reference
contentType
rawScores
consumptionPreferences