File size: 2,902 Bytes
7d200f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd06523
7d200f3
cd06523
7d200f3
cd06523
7d200f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
# Function to generate captcha
def generate_captcha(transaction_id):
    url = "https://tathya.uidai.gov.in/audioCaptchaService/api/captcha/v3/generation"
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "verifyAadhaar_IN",
        "Connection": "keep-alive",
        "Content-Type": "application/json",
        "DNT": "1",
        "Origin": "https://myaadhaar.uidai.gov.in",
        "Referer": "https://myaadhaar.uidai.gov.in/",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36 Edg/125.0.0.0",
        "appid": "MYAADHAAR",
        "sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": '"Android"',
        "x-request-id": str(transaction_id),  # Using the UUID
    }
    data = {
        "captchaLength": "6",
        "captchaType": "1",
        "audioCaptchaRequired": False
    }
    try:
        print("Generating Captcha from UIDAI")
        response = requests.post(url, headers=headers, json=data)
        print(response)
        response.raise_for_status()  # Raise HTTPError for bad responses
        print(response.json())
        return response.json()
    except requests.RequestException as e:
        print(f"Error in Captcha Generation from UIDAI: {e}")
        return {"error": str(e)}

# Function to validate Aadhaar
def validate_aadhaar(data):
    url = "https://tathya.uidai.gov.in/uidVerifyRetrieveService/api/verifyUID"
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "en_IN",
        "Connection": "keep-alive",
        "Content-Type": "application/json",
        "DNT": "1",
        "Origin": "https://myaadhaar.uidai.gov.in",
        "Referer": "https://myaadhaar.uidai.gov.in/",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36 Edg/125.0.0.0",
        "appid": "MYAADHAAR",
        "sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": '"Android"',
        "x-request-id": data.get("transactionId"),
    }

    try:
        response = requests.post(url, headers=headers, json=data)
        response.raise_for_status()  # Raise HTTPError for bad responses
        return response.json()
    except requests.RequestException as e:
        print(f"Error in Aadhaar Validation: {e}")
        return {"status": response.status_code, "message": str(e)}