#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, urllib, urllib2, json
f = open("test.txt","w")
url = 'http://apis.baidu.com/apistore/idlocr/ocr'
data = {}
data['fromdevice'] = "pc"
data['clientip'] = "10.10.10.0"
data['detecttype'] = "LocateRecognize"
data['languagetype'] = "CHN_ENG"
data['imagetype'] = "1" #`2`代表图片原文件(只支持JPG)
data['image'] = "" ##image base64 data
decoded_data = urllib.urlencode(data)
req = urllib2.Request(url, data = decoded_data)
req.add_header("Content-Type", "application/x-www-form-urlencoded")
req.add_header("apikey", "自己的apikey")
resp = urllib2.urlopen(req)
content = resp.read()
if(content):
print(content)
f.write(content)