How to "post" image URL instead of Image to Vision Cognitive API?

1.1k views Asked by At

Here is the code i used:

conn = httplib.HTTPSConnection('api.projectoxford.ai')
conn.request("POST", "/vision/v1.0/ocr?%s" % params,"{'Url':'my_url_xxxxxxxxxx'}", headers_1)
response = conn.getresponse()
data = response.read()
print(data)

This is the error I got:

{
    "code":"InvalidImageUrl",
    "requestId":"3e074556-dd52-4965-b250-e821b7fb6c27",
    "message":"Image URL is not accessible."
}
2

There are 2 answers

3
cthrash On

Your payload needs to be properly cased: "{'url':'https://s-media-cache-ak0.pinimg.com/originals/8c/1b/82/8c1b825d2d0750957098c8a4a879d53f.jpg'}", note lower-case url, not Url.

0
Renu M.J On

The error got corrected. I used small cps 'url' instead of "Url" and also changed type to json

api details

headers_1 = { 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': '*************************' #My valid Key }


conn = httplib.HTTPSConnection('api.projectoxford.ai') conn.request("POST", "/vision/v1.0/ocr?%s" % params,"{'url':'my_url_xxxxxxxxxx'}", headers_1) response = conn.getresponse() data = response.read() print(data)