IBM Cloud Functions:找不到"ibm

编程入门 行业动态 更新时间:2024-10-10 14:27:31
本文介绍了IBM Cloud Functions:找不到"ibm-watson/auth"软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 IBM Cloud函数从 IBM Watson Discovery 请求一些结果.此处有一个很好的GitHub存储库关于如何调用此存储库.但是,在功能中设置动作的方式中,出现错误,消息为找不到模块'ibm-watson/auth'.我了解消息内容,但是如果您查看GitHub存储库,就会发现我执行了完全相同的步骤.我的IBM Cloud功能代码是:

I'm using IBM Cloud functions for requesting some results from IBM Watson Discovery. There is a very good GitHub repo here about how can we invoke this. However, on the way of setting the action in the function an error with message Cannot find module 'ibm-watson/auth' occurs. I understand what the message says, but if you check the GitHub repo, you see that I apply exactly the same steps. My IBM Cloud function code is:

case 'doc_info': var user_input = params.user_input; const watson = require('ibm-watson/sdk'); const { CloudantV1 } = require('@cloudant/cloudant'); const DiscoveryV1 = require('ibm-watson/discovery/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); //const { IamAuthenticator } = require('ibm-cloud-sdk-core'); try { const discovery = new DiscoveryV1({ // Initializing Discovery version: '2020-11-24', authenticator: new IamAuthenticator({ apikey: params.apiKeyDisco, }), serviceUrl: params.urlDisco, }); const cloudant = new CloudantV1({ // Initializing CloudantV1 authenticator: new IamAuthenticator({ apikey: params.apiKeyCloudant }) }); cloudant.setServiceUrl(params.urlCloudant); // ... return { answer: "Simple test" }; } catch (err) { console.log(err) return Promise.reject({ statusCode: 500, headers: { 'Content-Type': 'application/json' }, body: { message: err.message }, }); } break;

即使从 ibm-cloud-sdk-core 包中调用 IamAuthenticator ,我也尝试过,但是错误是 IamAuthenticator不是构造函数.我们该如何解决呢?

I've tried even with calling IamAuthenticator from the ibm-cloud-sdk-core package, but then the error is IamAuthenticator is not a constructor. How can we solve this?

推荐答案

在此处查看 IBM Cloud Functions中可用的运行时环境.根据Node.js版本的不同,IBM Watson SDK的版本也有所不同.如文档中所述,Node.js 12运行时具有您正在寻找的具有IAM身份验证功能的较新SDK.Node.js 10运行时具有V4.x IBM Watson SDK.

See here for the runtime environments available in IBM Cloud Functions. Depending on the Node.js version, there are different versions of the IBM Watson SDK. As stated in the docs, the Node.js 12 runtime has the newer SDK with the IAM Authentication functionality you are looking for. The Node.js 10 runtime has the V4.x IBM Watson SDK.

因此,您需要使用以下旧方法(已记录)进行身份验证,或升级到Node.js 12运行时.

Thus, you need to either use the old (documented) way of authenticating, or move up to the Node.js 12 runtime.

如果您使用旧的用户名/密码身份验证,并且仅具有IAM API密钥,请使用 iamapikey 作为用户名,并使用API​​密钥作为密码.

If you use the old username / password authentication and only have an IAM API key, use iamapikey as username and the API key as password.

更多推荐

IBM Cloud Functions:找不到"ibm

本文发布于:2023-11-26 19:23:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   Cloud   IBM   Functions   ibm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!