程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

A keyerror problem in Python

編輯:Python

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 )

print(b['words_result']['number'])

fo.write("%d.jpg-%s \n" %(i,b['words_result']['number']))

i = i + 1

#else : #  print(" error")

#fo.close()


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved