[Python] How to generate aadhaar card data from qr code

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to generate user data from aadhaar qr code, i'm trying the 2 methods

    from aadhaar.secure_qr import extract_data

    extracted_data = extract_data(int(qrData))
    print(extracted_data.text_data)

    # and

    from pyaadhaar.decode import AadhaarSecureQr

    secure_qr = AadhaarSecureQr(int(normal_int))
    print(secure_qr.data)


    Both are almost similar methods, but when I try to exctract data from the qr on the uidai site (3181 chars) and this sample data (3166 chars) the data is succesfully generated, but when I try to scan my own aadhaar qr (3142 chars), the following errors occur

    Traceback (most recent call last):
    File "...", line 18, in <module>
    extracted_data = extract_data(int(qrData))
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\aadhaar\secure_qr\extractor.py", line 330, in extract_data
    return data_extractor.extract()
    ^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\aadhaar\secure_qr\extractor.py", line 318, in extract
    text_data=self._make_text_data(),
    ^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\aadhaar\secure_qr\extractor.py", line 212, in _make_text_data
    reference_id=self._make_reference_id(extracted_text_data["reference_id"]),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\aadhaar\secure_qr\extractor.py", line 197, in _make_reference_id
    timestamp=datetime.strptime(extracted_data[4:], "%Y%m%d%H%M%S%f"),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\_strptime.py", line 554, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\_strptime.py", line 333, in _strptime
    raise ValueError("time data %r does not match format %r" %
    ValueError: time data '' does not match format '%Y%m%d%H%M%S%f'

    # and

    Traceback (most recent call last):
    File "...", line 18, in <module>
    secure_qr = AadhaarSecureQr(int(normal_int))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyaadhaar\decode.py", line 27, in __init__
    self._extract_info_from_decompressed_array()
    File "C:\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyaadhaar\decode.py", line 52, in _extract_info_from_decompressed_array
    self.data['aadhaar_last_digit'] = self.data['referenceid'][3]
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^
    IndexError: string index out of range


    I want to know the solution to the problem or any other methods to do the same. Thank you : )

    Continue reading...

Compartilhe esta Página