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)}