我目前在以下环境中使用Watson Visual Recognition API,但收到403无效的凭证错误。 供您参考,我正在VMware Workstation 15.5.1中的Ubuntu Server 16.04.6 LTS上运行此程序。 Node js代码来自URL下面的IBM Cloud网页,我在我的凭证中输入api密钥。 我已经通过使用以下命令并遵循the guide安装了npm。
npm install --save watson-developer-cloud
var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
var fs = require('fs');
var visualRecognition = new VisualRecognitionV3({
version: '2018-03-19',
iam_apikey: 'Hy-N8Lxxxxxxxxxxxxxxxxxxxxxxxxxxxx' // used api key in my credentials
});
var url= 'https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/640px-IBM_VGA_90X8941_on_PS55.jpg';
var params = {
url: url,
};
visualRecognition.classify(params, function(err, response) {
if (err) {
console.log(err);
} else {
console.log(JSON.stringify(response, null, 2))
}
});
当我在命令行中执行命令node {filename}.js
时,出现如下错误消息。对于此错误,代码为403,并且当我输入错误的API密钥时,会出现错误代码400,因此我认为错误不在于错误的api密钥。
Forbidden: Access is denied due to invalid credentials.
at formatError (/home/byungmin/visual_recognition/node_modules/ibm-cloud-sdk -core/lib/requestwrapper.js:111:17)
at /home/byungmin/visual_recognition/node_modules/ibm-cloud-sdk-core/lib/req uestwrapper.js:259:19
at processTicksAndRejections (internal/process/task_queues.js:94:5) {
name: 'Forbidden',
code: 403,
message: 'Access is denied due to invalid credentials.',
body: '{"code":403,"error":"Forbidden"}',
headers: {
'content-type': 'application/json',
'content-length': '34',
'strict-transport-security': 'max-age=31536000; includeSubDomains;',
'x-edgeconnect-midmile-rtt': '224',
'x-edgeconnect-origin-mex-latency': '49',
date: 'Fri, 21 Feb 2020 12:56:10 GMT',
connection: 'close'
}
}
感谢您能帮助我找到解决此问题的方法。
答案 0 :(得分:1)
为精简版帐户尝试此操作:
const fs = require('fs');
const { IamAuthenticator } = require('ibm-watson/auth');
var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
var visualRecognition = new VisualRecognitionV3({
authenticator: new IamAuthenticator({
apikey: 'Hy-N8Lxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}),
url: 'https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/640px-IBM_VGA_90X8941_on_PS55.jpg',
});
var params = {
url: url,
};
visualRecognition.classify(params, function(err, response) {
if (err) {
console.log(err);
} else {
console.log(JSON.stringify(response, null, 2))
}
});
答案 1 :(得分:0)
这是“免费”计划吗?使用该计划,您一个月内只能接受1000张图像进行训练和标记。您极有可能已达到该限制。将您的帐户升级为标准帐户将保留所有受过训练的分类器,并允许您随意使用。
答案 2 :(得分:0)
如果精简版计划超支不是问题,请检查是否在=MIN(IF(C2=MINIFS(C:C,A:A,A2),MINIFS(B:B,A:A,A2)-MINIFS(C:C,A:A,A2),0)*5,50)
指定了基本URL,并且该URL与所用API密钥的凭据中显示的URL匹配。有关详细信息,请参见API reference。