如何将图像URL而不是Image“发布”到Vision Cognitive API?

时间:2016-12-19 11:10:14

标签: python-2.7 ocr microsoft-cognitive

以下是我使用的代码:

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)

这是我得到的错误:

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

2 个答案:

答案 0 :(得分:0)

您的有效负载需要正确设置:"{'url':'https://s-media-cache-ak0.pinimg.com/originals/8c/1b/82/8c1b825d2d0750957098c8a4a879d53f.jpg'}",请注意小写url,而不是Url

答案 1 :(得分:0)

错误得到纠正。 我使用小cps'url'而不是“Url”,并将类型更改为json

api详情

headers_1 = {     'Content-Type':'application / json',     'Ocp-Apim-Subscription-Key':'*************************'#我的有效密钥 }

conn = httplib.HTTPSConnection('api.projectoxford.ai') conn.request(“POST”,“/ vision / v1.0 / impr?%s”%params,“{'url':'my_url_xxxxxxxxxx'}”,headers_1) response = conn.getresponse() data = response.read() 打印(数据)