From dde607d1a86e15524aaed12b14d06448e26c9ce8 Mon Sep 17 00:00:00 2001 From: Nitwix Date: Sat, 12 Apr 2025 22:29:54 +0200 Subject: [PATCH] Null check mrz_obj --- utils/parsers/passport_parser.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/utils/parsers/passport_parser.py b/utils/parsers/passport_parser.py index 5aa9fea..1b392c2 100644 --- a/utils/parsers/passport_parser.py +++ b/utils/parsers/passport_parser.py @@ -23,13 +23,15 @@ def process_passport(passport_b64: str) -> str: image = Image.open(io.BytesIO(image_bytes)) tesseract_text = pytesseract.image_to_string(image, lang='eng') - out_dict = { - "country": mrz_obj.country, - "names": mrz_obj.names, - "number": mrz_obj.number, - "surname": mrz_obj.surname, - "mrz": mrz_obj.aux["text"], - "raw": tesseract_text - } + out_dict = {} + if not mrz_obj is None: + out_dict = { + "country": mrz_obj.country, + "names": mrz_obj.names, + "number": mrz_obj.number, + "surname": mrz_obj.surname, + "mrz": mrz_obj.aux["text"], + } + out_dict["raw"] = tesseract_text out = json.dumps(out_dict) return out \ No newline at end of file