【问题标题】:cognitive computer vision api, Initial 202 response from api call, then 401 error from Operation-Location认知计算机视觉 api,来自 api 调用的初始 202 响应,然后来自 Operation-Location 的 401 错误
【发布时间】:2020-02-02 10:10:54
【问题描述】:

在 reactjs 项目中运行,这是我当前的代码:

         let response = await fetch('https://apis-cv.cognitiveservices.azure.com/vision/v1.0/recognizeText?handwriting=true', {
          method: 'POST',
          headers: { 'Content-Type': 'application/octet-stream', 'Ocp-Apim-Subscription-Key': '<MY KEY HERE>' },
          body: this.makeblob(event.target.result)
        });
        console.log(response);

我的初始响应状态为 202:给出了 Operation-Location。 (即https://apis-cv.cognitiveservices.azure.com/vision/v1.0/textOperations/a60b86b2-bf85-4e3b-8beb-65dc075e81d7) 但 Operation-Location 会导致 401:

 {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}} 

我也尝试过使用 url 和 content-type: application/json 并得到相同的结果。

【问题讨论】:

    标签: azure computer-vision azure-cognitive-services


    【解决方案1】:

    错误消息非常清楚:当您尝试获取 TextOperations 的结果时,您忘记在第二个查询中添加“Ocp-Apim-Subscription-Key”。

    您能否添加您如何尝试获得结果的实现?

    【讨论】:

    • 谢谢!我只是在浏览器中访问 URL。现在我再次使用 fetch 和我的标题中的键,它工作了! (对我来说,我必须从我阅读的文档中执行此操作并不明显)
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 2016-08-06
    • 2020-05-24
    • 1970-01-01
    相关资源
    最近更新 更多