from requests_toolbelt import MultipartEncoder
import requests,json
import glob,os
def picupload(picname):
m = MultipartEncoder({'image': (picname, open(picname, 'rb'), 'image/jpeg')})
params = {'app_id':'9999','secret_key':'a397454eb95b4b13a60ce98d48abac27'}
response = requests.post('https://api.saic-itech.com/rest/image/vehicle-license',
params=params,
data=m,
headers={'Content-Type': m.content_type})
try:
responsejson = json.loads(response.text)
#print(responsejson)
vehiclenumber=responsejson["result"][0][0]["characters"]
#print(vehiclenumber)
#print("2: ", response.request.body)
# print("3: ", response.request.headers)
return (vehiclenumber)
except IndexError:
return "nol"
if __name__ == '__main__':
picupload("./jpg/皖A77V53.jpg")
""""
for fname in glob.glob("./jpg/*.jpg"):
(filepath, tempfilename) = os.path.split(fname)
(filename, extension) = os.path.splitext(tempfilename)
if picupload(fname)==filename:
print("ok,"+picupload(fname)+"="+filename)
else :
print("ng")
"""
python遍历文件夹下的图片上传
最新推荐文章于 2024-06-13 19:43:50 发布