0

I am just getting started with microsoft's computer vision OCR api, Subscription key and image url is working fine on https://westus.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc/console

But I am getting the following error when using the python code

{"statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."}

I have tried my best to figure out the error but failed.

What am I doing wrong?

Thanks in advance.

import httplib, urllib, base64
headers = {
 # Request headers
 'Content-Type': 'application/json',
 'Ocp-Apim-Subscription-Key': '{1111460aa78d4b27****************}',
}
params = urllib.urlencode({
 # Request parameters
 'language': 'unk',
 'detectOrientation ': 'true',
})
try:
 conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
 conn.request("POST", "/vision/v1.0/ocr?%s" % params, "{\"url\":\"https://s-media-cache-ak0.pinimg.com/originals/fb/e6/56/fbe65691cb66c6f035a859d9671c3fe5.jpg\"}", headers)
 response = conn.getresponse()
 data = response.read()
 print(data)
 conn.close()
except Exception as e:
 print("[Errno {0}] {1}".format(e.errno, e.strerror))
asked Feb 9, 2017 at 16:08

1 Answer 1

1

You need to drop the curly braces for the API key value, i.e.:

headers = {
 # Request headers
 'Content-Type': 'application/json',
 'Ocp-Apim-Subscription-Key': '1111460aa78d4b27****************',
}
answered Feb 9, 2017 at 17:50
Sign up to request clarification or add additional context in comments.

1 Comment

cthrash Thanks Brother :) I think I have to try harder :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.