Troubleshooting of Azure Cognitive Services API: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
(Created page with "[https://azure.microsoft.com/zh-tw/services/cognitive-services/computer-vision/ 電腦視覺 | Microsoft Azure]: [https://docs.microsoft.com/zh-tw/azure/cognitive-services/Com...")
 
mNo edit summary
Line 1: Line 1:
[https://azure.microsoft.com/zh-tw/services/cognitive-services/computer-vision/ 電腦視覺 | Microsoft Azure]: [https://docs.microsoft.com/zh-tw/azure/cognitive-services/Computer-vision/quickstarts-sdk/client-library?pivots=programming-language-rest-api&tabs=visual-studio 快速入門:光學字元辨識 (OCR) 用戶端程式庫或 REST API - Azure Cognitive Services | Microsoft Docs] 支援中文<ref>[https://docs.microsoft.com/zh-tw/azure/cognitive-services/computer-vision/language-support#optical-character-recognition-ocr 語言支援 - 電腦視覺 - Azure Cognitive Services | Microsoft Docs]</ref>
[https://azure.microsoft.com/zh-tw/services/cognitive-services/computer-vision/ 電腦視覺 | Microsoft Azure]


== How to fix the error: invalid subscription key or wrong API endpoint ==
== How to fix the error: invalid subscription key or wrong API endpoint ==
Line 9: Line 9:
* Verify the API endpoint
* Verify the API endpoint
* Verify the subscription key and add to request header
* Verify the subscription key and add to request header
Example command edited from the API document<ref>[https://docs.microsoft.com/zh-tw/azure/cognitive-services/Computer-vision/quickstarts-sdk/client-library?pivots=programming-language-rest-api&tabs=visual-studio 快速入門:光學字元辨識 (OCR) 用戶端程式庫或 REST API - Azure Cognitive Services | Microsoft Docs]</ref>
<pre>
curl -v -X POST "<API endpoint>" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" --data-ascii "{\"url\":\"<image URL>\"}"
</pre>





Revision as of 13:53, 21 April 2022

電腦視覺 | Microsoft Azure

How to fix the error: invalid subscription key or wrong API endpoint

Error message

{"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."}}

Solution:

  • Verify the API endpoint
  • Verify the subscription key and add to request header

Example command edited from the API document[1]

curl -v -X POST "<API endpoint>" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" --data-ascii "{\"url\":\"<image URL>\"}"


How to fix the error: Unsupported media type

Error message

{"error":{"code":"BadArgument","message":"Unsupported media type."}}

Solution: Add this item to request header

Content-Type: application/json

References


Troubleshooting of ...

Template