【问题标题】:Microsoft Text Analytics API (v2.1) sample code does not workMicrosoft 文本分析 API (v2.1) 示例代码不起作用
【发布时间】:2023-03-08 20:35:01
【问题描述】:

我想使用 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'}} 有什么问题?

【问题讨论】:

    标签: azure microsoft-cognitive jsonresponse


    【解决方案1】:

    我在这方面的分析方面玩的不多,所以我可能完全偏离了基础,但在我看来,你已经把“文本/分析”加倍了。

    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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2012-12-28
    • 2017-04-21
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多