【问题标题】:API call IBM Watson Natural Language Understanding-xq - Python or PostmanAPI 调用 IBM Watson Natural Language Understanding-xq - Python 或 Postman
【发布时间】:2019-01-02 11:10:44
【问题描述】:

我很难连接到 IBM Watson API for Natural Language Understanding。

我已将其添加到我的 IAM 账户的资源列表中。我已经进入带有示例 POST 请求以连接到 API 的页面,但我似乎无法进行身份验证。我已经从这个请求中删除了 API 密钥,但是在页面中提供了密钥,所以我很难知道它为什么不起作用

curl -X POST -u "#######" \
-H "Content-Type: application/json" \
-d '{  "text": "I still have a dream. It is a dream deeply rooted in the 
American dream. I have a dream that one day this nation will rise up and 
live out the true meaning of its creed: \"We hold these truths to be 
self-evident, that all men are created equal.\"",  "features": {    
"sentiment": {},    "keywords": {}  }}' \
"https://gateway-lon.watsonplatform.net/natural-language- 
understanding/api/v1/analyze?version=2018-03-19"

我尝试将其粘贴到 Postman 中,但我只收到 401 Unauthorized 响应,这让我认为这是 IAM 帐户页面中的内容,但他们更改了界面并没有更新文档,我我在兜圈子,因为说明与菜单不符。

任何指针将不胜感激。我打算通过 Python 进行查询,所以我希望一旦我能够解决身份验证问题,就像从 Postman 中复制 Python 代码一样简单

【问题讨论】:

  • 不,让 Python 工作是第 2 步,我被困在第 1 步,即使用 Postman 测试 API 身份验证。在处理 Python 代码之前,我倾向于先检查我的身份验证是否有效,然后我可以隔离哪个元素失败。不过我会在之前给出它,因为您的链接似乎表明 SDK 似乎在处理令牌...所以谢谢,我会告诉您...
  • 我试了一下,但得到了“引发 WatsonApiException(response.status_code,message=error_message,httpResponse=response)watson_developer_cloud.watson_service.WatsonApiException:错误:找不到提供的 API 密钥,代码:400”
  • 搞定了。非常感谢。请参阅下面关于删除和重新创建 API 密钥的回答

标签: python-3.x api nlp ibm-watson


【解决方案1】:

您的 -u 凭据应该是:

-u "apikey:#######"

根据 API 文档 - https://cloud.ibm.com/apidocs/natural-language-understanding#authentication

【讨论】:

  • 是的,我对我过于热情了#### apikey,IBM 网站在 curl 代码 iexample 中包含 -u "apikey:#######",这就是我试图使用。当我直接从 IBM 站点粘贴代码时,Postman 无法处理代码的 -u 元素。 Postman 中的授权是“从父级继承身份验证”,我不确定如何在 Postman 接口中生成 -u 部分。如果有人有建议,至少意味着我可以获得有效的响应而不是授权错误。目前我不能完全排除是否是我的 IAM 账户设置有问题。
【解决方案2】:

不知何故无法识别 API 凭据。我一定是在最初的 IAM 设置中做错了什么,这意味着当我删除凭据、重新创建它们然后复制新密钥时……一切都立即开始工作。关于原因的完整谜团,但希望这对某人有所帮助。这是我遵循的说明

https://console.bluemix.net/docs/services/natural-language-understanding/getting-started.html#getting-started-tutorial

我按照 Simon O'Doherty 的建议使用了 SDK

这也可能与我进入“管理”>>“帐户”并删除了我尝试按照此处的“IAM 入门”说明创建的任何访问组和服务 ID 有关,其中我怀疑可能是让我感到困惑的原因

IAM getting started (not required)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 2019-11-27
    • 2015-12-13
    • 2016-08-12
    • 1970-01-01
    • 2016-11-28
    相关资源
    最近更新 更多