azure - Microsoft 文本分析 API (v2.1) 示例代码不起作用
问题描述
我想使用 Microsoft Azure 的情绪分析 API。我使用他们的示例代码(https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/quickstarts/python)如下。
# -*- coding: utf-8 -*
import requests
# pprint is used to format the JSON response
from pprint import pprint
import os
subscription_key = "*********"
endpoint = "https://westcentralus.api.cognitive.microsoft.com/text/analytics"
sentiment_url = endpoint + "/text/analytics/v2.1/sentiment"
documents = {"documents": [
{"id": "1", "language": "en",
"text": "I had a wonderful experience! The rooms were wonderful and the staff was helpful."},
{"id": "2", "language": "en",
"text": "I had a terrible time at the hotel. The staff was rude and the food was awful."},
{"id": "3", "language": "es",
"text": "Los caminos que llevan hasta Monte Rainier son espectaculares y hermosos."},
{"id": "4", "language": "es",
"text": "La carretera estaba atascada. Había mucho tráfico el día de ayer."}
]}
headers = {"Ocp-Apim-Subscription-Key": subscription_key}
response = requests.post(sentiment_url, headers=headers, json=documents)
sentiments = response.json()
pprint(sentiments)
但它只返回{'error': {'code': '404', 'message': 'Resource not found'}}
有什么问题?
解决方案
我在这方面的分析方面玩的不多,所以我可能完全偏离了基础,但在我看来,你已经把“文本/分析”加倍了。
endpoint = "https://westcentralus.api.cognitive.microsoft.com/text/analytics"
sentiment_url = endpoint + "/text/analytics/v2.1/sentiment"
将给出 https://westcentralus.api.cognitive.microsoft.com/text/analytics/text/analytics/v2.1/sentiment的最终结果
它可能应该只是:
https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.1/sentiment
推荐阅读
- r - 如何“在其他图形选项中包装 [DCdensity] 以修改绘图”?rdd 包
- ios - 如果未安装应用程序,是否可以使用通用链接将用户重定向到特定内容?
- android - 在 Cordova 应用程序中禁用文本选择输入
- javascript - 如何在javascript的foreach语句中初始化id?
- database - 为多个独特的应用程序设计一个通用数据库
- spyder - 在 spyder (python 3.6) 中突出显示#text (comments)
- javascript - 根据特定条件制作不同传奇副作用的正确方法是什么?
- java - 使用嵌套的 for 循环将字符串数组中的每个字符串与一个用户输入字符串进行比较
- jmeter-plugins - 为什么 HLS 采样器错误显示空白错误
- android - 不幸的是,应用程序已停止 Facebook 登录