1 Star 0 Fork 0

Zsheng/baidudownload

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
xal.py 941 Bytes
一键复制 编辑 原始数据 按行查看 历史
tianzhongsheng 提交于 2020-03-09 12:51 . ‘1’
#python3
import urllib.request
import urllib.error
import urllib.parse
import json
import time
import base64
with open('3.jpeg', 'rb') as f: # 以二进制读取本地图片
data = f.read()
encodestr = str(base64.b64encode(data),'utf-8')
#请求头
headers = {
'Authorization': 'APPCODE 712d406485a44077a7e72d7b03a2af36',
'Content-Type': 'application/json; charset=UTF-8'
}
def posturl(url,data={}):
try:
params=json.dumps(dict).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-invoice.taobao.com/ocrservice/invoice"
dict = {'img': encodestr}
html = posturl(url_request, data=dict)
print(html)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zsheng168/baidudownload.git
git@gitee.com:zsheng168/baidudownload.git
zsheng168
baidudownload
baidudownload
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385