【发布时间】: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 SDK吗? github.com/watson-developer-cloud/python-sdk
-
不,让 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