【问题标题】:OpenWhisk (CloudFunction) binding to Watson Conversation and the use of username password in the SDKOpenWhisk (CloudFunction) 绑定到 Watson Conversation 以及 SDK 中用户名密码的使用
【发布时间】:2018-01-24 08:40:31
【问题描述】:

我有一个调用 Watson 对话服务的 IBM Cloud Function (OpenWhisk)。 我们正在使用 JAVA JAVA SDK (https://github.com/watson-developer-cloud/java-sdk) 的文档表明将从绑定中获取凭据。

当我列出绑定时,我得到了这个:

>bx wsk action get talksmall parameters
ok: got action talksmall, displaying field parameters
[
    {
        "key": "__bx_creds",
        "value": {
            "conversation": {
                "credentials": "Credentials-SmallTalk",
                "instance": "<INSTANCE>",
                "password": "<PASSWORD>",
                "url": "https://gateway.watsonplatform.net/conversation/api",
                "username": "<USERNAME>"
            }
        }
    }
]

但是当我像这样使用 SDK 时:

Conversation conversationService = new Conversation(Conversation.VERSION_DATE_2017_05_26);

我收到一个错误

{
  "error": "An error has occured while invoking the action (see logs for details): java.lang.IllegalArgumentException: apiKey or username and password were not specified"
}

当我添加行时:

conversationService.setUsernameAndPassword(userName, password);

它有效。 也许 VCAP_Service 绑定方式不适用于 Cloud Functions ? Cloud Function 在相同的 IBM Cloud 组织和空间中运行。

【问题讨论】:

    标签: ibm-watson openwhisk ibm-cloud-functions


    【解决方案1】:

    我针对有关“在 Bluemix 中运行”的 SDK 文档提出了一个问题。 IBM Cloud 提供基础架构、OpenWhisk / Cloud Functions、Cloud Foundry 等。 Bluemix 源自 Cloud Foundry,通过 VCAP_SERVICE 自动绑定是 Cloud Foundry 的一项功能。

    根据我在 Python 和 Node.js 中使用 IBM Cloud Functions 的经验,您需要调用 API 函数来显式设置凭证。借助服务绑定功能,您可以轻松地使供应服务的凭证可用于 IBM Cloud Functions 中的上下文,如上面的代码所示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      相关资源
      最近更新 更多