为了更好的阅读体验和代码可读性,建议您对代码进行格式化,如下所示:

encoding:utf-8

import requests import base64 import requests import json

def main(): url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=bhNphgcigCgpRKbPDM4tu5nF&client_secret=MlA31Q8jQs65YGAXEnCd2lC2tVnaQhml"

payload = ""
headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
return response

if name == 'main': response = main() x = json.loads(response.text) m = x["refresh_token"]

'''
通用文字识别(高精度版)
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
# 二进制方式打开图片文件
f = open('z\\4.img', 'rb')
img = base64.b64encode(f.read())

params = {"image": img}
access_token = m
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)

print(response.json())  # 将结果打印出
# encodingutf-8import requestsimport base64import requestsimport jsondef main url = httpsaipbaidubcecomoauth20tokengrant_type=client_credentials&client_id=bhNphgcigCgpRKbPDM4tu5nF&client_secret=MlA

原文地址: https://www.cveoy.top/t/topic/fj9R 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录