官网:
文档地址 :/docs/doc-oc…
在Python中调用api.
#/usr/bin/env python#coding=utf8import httplibimport md5import urllibimport urllib2import randomimport jsonimport base64appKey = '应用程序key'secretKey = '应用程序秘钥'httpClient = Nonetry:f=open(r'd:\1.png','rb') #二进制方式打开图文件 需要用户在d:\1.png 放这个图片并且里面得有文字img=base64.b64encode(f.read()) #读取文件内容,转换为base64编码 f.close()detectType = '10011'imageType = '1'langType = 'zh-en'#ensalt = random.randint(1, 65536)sign = appKey+img+str(salt)+secretKeym1 = md5.new()m1.update(sign)sign = m1.hexdigest()data = {'appKey':appKey,'img':img,'detectType':detectType,'imageType':imageType,'langType':langType,'salt':str(salt),'sign':sign}data = urllib.urlencode(data)req = urllib2.Request('/ocrapi',data)#response是HTTPResponse对象response = urllib2.urlopen(req)readJson = response.read()print unicode(readJson, "utf-8")except Exception, e:print efinally:if httpClient:httpClient.close()复制代码