#python2
import urllib, sys
import ssl



#python3
import urllib.request
import urllib.parse
import json
import time
import base64
with open('/home/chenyukun/healthCode/jitimg/gfkz72uu6l4_1667954724082_cityImage.jpg', 'rb') as f:  # 以二进制读取本地图片
    data = f.read()
    encodestr = str(base64.b64encode(data),'utf-8')
#请求头
headers = {
    'Authorization': 'APPCODE ed8b467a3948407eba929b0dd329f1f5',
    'Content-Type': 'application/json; charset=UTF-8'
}
def posturl(url,data=None):
    if data is None:
        data = {}
    try:
        params=json.dumps(data).encode(encoding='UTF8')
        req = urllib.request.Request(url, params, headers)
        r = urllib.request.urlopen(req)
        html =r.read()
        r.close();
        return html.decode("utf8")
    except urllib.error.HTTPError as e:
        print(e.code)
        print(e.read().decode("utf8"))
    time.sleep(1)
if __name__=="__main__":
    url_request="https://ocrapi-advanced.taobao.com/ocrservice/advanced"
    dict = {'img': encodestr}

    html = posturl(url_request, data=dict)
    print(html)