It was used get This is the effect after the function
Then it will report keyerror
Source code :import requests
import base64
import json
import os
from os import path
# Create goals txt file
file_name = "/Users/wangyanjuan/Desktop/pythonread/car_plate.txt"
fo = open(file_name,'w')
i = 1
# Traversal folder
dir_name = "/Users/wangyanjuan/Desktop/photoread/"
list_file = os.listdir(dir_name)
for x in list_file:
# Extract the license plate
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate%22
file = dir_name + x
f = open(file, 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = '24.1fc9f87fbac1b09e48c9045679fa9e87.2592000.1659157791.282335-26582147'
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)
if response:
# Write license plate
b = response.json()
print(b.get("words_result","111"))
( The following is the comment )
#else : # print(" error")
#fo.close()