我一直在尝试针对IBM Watson Tone Analyzer服务运行查询,并不断收到我的服务凭据无法识别的错误。
我确信我输入了正确的凭据。以下是我获取服务凭据的步骤:
我多次执行这些步骤但仍然遇到同样的错误:
watson_developer_cloud.watson_developer_cloud_service.WatsonException: Unauthorized: Access is denied due to invalid credentials
我真的很感激这里的见解。
答案 0 :(得分:2)
我只能运行测试而没有任何错误。以下是我采取的步骤:
<强> 1。创建了一个新的IBM Watson Tone Analyzer实例:
<强> 2。查看了服务凭据页面: (我已将用户名更改为&#34; abcuser&#34;以及密码为&#34; abcpass&#34;对于此示例。)
第3。我运行此curl命令来测试我的服务:
curl -u "{username}":"{password}" -H "Content-Type: application/json" -d "{\"text\": \"Hi Team, I know the times are difficult! Our sales have been disappointing for the past three quarters for our data analytics product suite. We have a competitive data analytics product suite in the industry. But we need to do our job selling it! \"}" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19"
所以更换用户名和密码,我得到......
curl -u "abcuser":"abcpass" -H "Content-Type: application/json" -d "{\"text\": \"Hi Team, I know the times are difficult! Our sales have been disappointing for the past three quarters for our data analytics product suite. We have a competitive data analytics product suite in the industry. But we need to do our job selling it! \"}" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19"
<强> 4。最后,我得到了这样的答复:
{
"document_tone":{
"tone_categories":[
{
"tones":[
{
"score":0.455891,
"tone_id":"anger",
"tone_name":"Anger"
},
{
"score":0.156707,
"tone_id":"disgust",
"tone_name":"Disgust"
},
{
"score":0.17315,
"tone_id":"fear",
"tone_name":"Fear"
},
{
"score":0.190073,
"tone_id":"joy",
"tone_nam e":"Joy"
},
{
"score":0.291627,
"tone_id":"sadness",
"tone_name":"Sadness"
}
],
"category_id":"emotion_tone",
"category_name":"Emotion Tone"
},
{
"tones":[
{
"score":0.459,
"tone_id":"analytical",
"tone_name":"Analytical"
},
{
"score":0.0,
"tone_id":"confident",
"tone_name":"Confide nt"
},
{
"score":0.0,
"tone_id":"tentative",
"tone_name":"Tentative"
}
],
"category_id":"language_tone",
"category_name":"Language Tone"
},
{
"tones":[
{
"score":0.03,
"tone_id":"openness_big5",
"tone_name":"Openness"
},
{
"score":0.188,
"tone_id":"conscientiousness_big5",
"tone_nam e":"Conscientiousness"
},
{
"score":0.405,
"tone_id":"extraversion_big5",
"tone_name":"Extraversion"
},
{
"score":0.879,
"tone_id":"agreeableness_big5",
"tone_name":"Agreeableness"
},
{
"score":0.962,
"tone_id":"emotional_range_big5",
"tone_name":"Emotional Range"
}
],
"category_ id":"social_tone",
"category_name":"Social Tone"
}
]
}
}
修改强>
如果您在使用Python SDK时遇到问题,请尝试以下操作:
import json
from watson_developer_cloud import ToneAnalyzerV3Beta
tone_analyzer = ToneAnalyzerV3Beta(
url='https://gateway.watsonplatform.net/tone-analyzer/api',
username='USERNAME',
password='PASSWORD',
version='2016-02-11')
print(json.dumps(tone_analyzer.tone(text='I am very happy'), indent=2))
答案 1 :(得分:2)
从上面的帖子看,您看起来正在使用凭据做正确的事情,但尝试将其用于Tone Analyzer服务的Beta实例。
作为了解以下任何评论的背景知识:Tone Analyzer became "GA" on May 20th。以前,它是“Beta”。 Beta计划的网址为https://gateway.watsonplatform.net/tone-analyzer-beta/api
,而GA则使用.../tone-analyzer/api
(无-beta
)。另外,如果您正在使用Python,则有两个包装器:ToneAnalyzerV3Beta
(Beta)和ToneAnalyzerV3
(GA)。由于我们仍在转换,有些人仍然使用现有的Beta计划实例,并且Beta的包装器仍然存在。
最重要的是,Beta计划的凭据在GA中不起作用,反之亦然。
也就是说,您需要确保在任何地方始终使用GA或“标准”计划:
/tone-analyzer/api
(否-beta
)另一个细节(包装器将透明地处理)是?version
参数为2016-05-19
的最后一个API版本。您应该使用这个来获取最新功能......
Joe的回答非常详细,只是确保你区分这个Beta与GA的关系。如果您有更多问题,请添加其他评论。我希望这有帮助!