import urllib, sys import ssl from typing import Type import requests as rq from fastapi import HTTPException from utils.data_utils import JsDict from utils.print_utils import print_error class OcrData: log_id: int code: int msg: str class data: businessScope: str owner: str capital: str name: str expirationDate: str credit: str establishDate: str address: str companyType: str def ocr_business_license(image_url: str) -> Type[OcrData.data]: url = 'https://yingye.market.alicloudapi.com/ocr' appcode = 'bbe321c7b856499596223f63961c6ed3' # image_url = '''http://storage.api51.cn/demo/yyzz.jpg''' res = rq.post(url, params={'image': image_url}, headers={'Authorization': 'APPCODE ' + appcode, 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}) data: OcrData = JsDict(res.json()) print("识别结果",data) if data.code != 1: print("识别错误", data) raise HTTPException(detail='营业执照识别错误', status_code=303) else: return data.data