我正在执行下面的代码。.我提供了正确的API,但始终收到身份验证错误(下面提供)
这是代码段
// Example 1: sets up service wrapper, sends initial message, and
// receives response.
const AssistantV2 = require('ibm-watson/assistant/v2');
// Set up Assistant service wrapper.
const service = new AssistantV2({
iam_apikey: 'xxx', // replace with API key
version: '2019-02-28',
});
const assistantId = 'xxx'; // replace with assistant ID
let sessionId;
这是错误消息
C:\Users\User\Desktop\Insurancebot\test>node sample.js
{ Unauthorized: Access is denied due to invalid credentials.
at RequestWrapper.formatError (C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:219:21)
at C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:207:29
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Unauthorized',
code: 401,
message: 'Access is denied due to invalid credentials.',
body: '{"code":401,"error":"Unauthorized"}',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json',
'x-dp-transit-id': 'gateway02-3627341245',
'x-global-transaction-id': 'ffea405d5d0083b9d834d5bd',
'strict-transport-security': 'max-age=31536000;',
'x-dp-watson-tran-id': 'gateway02-3627341245',
'content-length': '37',
'x-edgeconnect-midmile-rtt': '110',
'x-edgeconnect-origin-mex-latency': '132',
date: 'Wed, 12 Jun 2019 04:46:49 GMT',
connection: 'close' } }
答案 0 :(得分:0)
{未经授权:由于凭据无效,访问被拒绝。
您的凭据错误。您可能要检查它们。 api键和assistantid可能要看,但还要注意用户名,大小写等。
答案 1 :(得分:0)
除了错误的IAM密钥外,最常见的原因是使用了错误的服务端点。
默认为美国,因此,例如,如果您在英国设置了助手,则应设置:url: ‘https://gateway-lon.watsonplatform.net/assistant/api’
完整列表在这里: