简体   繁体   中英

How to verify a passport . Can someone help me?

I'm a beginner, can someone help me with this error

from passporteye import read_mrz
import pytesseract as tess

tess.pytesseract.tesseract_cmd = r'C:\Users\USER-DAF005\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'
mrz = read_mrz("test.PNG")

mrz_data = mrz.to_dict()


nationality = str('Nationality :' + mrz_data['nationality'])
nationality = str(nationality)
print(nationality)

name = str('Given Name :' + mrz_data['names'])
names = str(name)
print(name)

surname = str('Surname :' + mrz_data['surname'])
surname = str(surname)
print(surname)

typePassp = str('Passport type :' + mrz_data['type'])
type = str(type)
print(typePassp)

country = str('Country code :' + mrz_data['country'])
country = str(country)
print(country)

birth = str('Date of birth :' + mrz_data['date_of_birth'])
birth = str(birth)
print(birth)

idNum = str('ID Number :' + mrz_data['personal_number'])
idNum = str(idNum)
print(idNum)

passNum = str('Passport Number :' + mrz_data['number'])
passNum = str(passNum)
print(passNum)

sex = str('Gender :' + mrz_data['sex'])
sex = str(sex)
print(sex)

expDate = str('Expiration date :' + mrz_data['expiration_date'])
expDate = str(expDate)
print(expDate)

print(mrz_data, file=open('passportdata.csv', "a"))

from mrz.generator.td3 import TD3CodeGenerator


code = TD3CodeGenerator(typePassp, country, surname, name, passNum, nationality, birth, sex, expDate, idNum)
result = str(code)
print(result)

The error message :

C:\Users\USER-DAF005\PycharmProjects\pythonProjectMRZ\venv\Scripts\python.exe C:/Users/USER-DAF005/PycharmProjects/pythonProjectMRZ/reconnaissance.py
Nationality :GAB
Given Name :AUSTEN JUNIOR
Surname :MOUITY CAKPO
Passport type :P<
Country code :GAB
Date of birth :900218
ID Number :<<<<<<<<<<<<<<
Passport Number :15GA84817
Gender :M
Expiration date :210803

Traceback (most recent call last):
  File "C:\Users\USER-DAF005\PycharmProjects\pythonProjectMRZ\reconnaissance.py", line 61, in <module>
    code = TD3CodeGenerator(typePassp, country, surname, name, passNum, nationality, birth, sex, expDate, idNum)
  File "C:\Users\USER-DAF005\PycharmProjects\pythonProjectMRZ\venv\lib\site-packages\mrz\generator\td3.py", line 124, in __init__
    self.document_type = document_type
  File "C:\Users\USER-DAF005\PycharmProjects\pythonProjectMRZ\venv\lib\site-packages\mrz\generator\_fields.py", line 46, in document_type
    self._document_type = check.document_type(value, self) if not self.force \
  File "C:\Users\USER-DAF005\PycharmProjects\pythonProjectMRZ\venv\lib\site-packages\mrz\base\string_checkers.py", line 94, in document_type
    raise DocumentTypeError(cause=string)
mrz.base.errors.DocumentTypeError: ('String was not recognized as a valid type of document.', 'Passport type :P<')

Process finished with exit code 1

You have created strings for printing that include the field label as well as the value:

typePassp = str('Passport type :' + mrz_data['type'])

This is fine for printing, but corrupts the values for all future use. Just pass mrz_data['type'] directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM