Skip to content
Snippets Groups Projects
grecaptcha_verify.py 1.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • from requests import post
    
    def grecaptcha_verify(request, skipCaptcha, recaptchaPrivateKey): #This function is used to verify the google recaptcha code, that is send to the server after submitting a new link
        if(skipCaptcha): return True #If recaptcha is disabled alwas return at this point true, which means response is verified
        captcha_rs = request.form.get('g-recaptcha-response')
        url = "https://www.google.com/recaptcha/api/siteverify" #The baseurl
        headers = {'User-Agent': 'DebuguearApi-Browser',} #Useragent doesn't matters, but is set here
        params = {'secret': recaptchaPrivateKey, 'response': captcha_rs} #As paramtere we send to google our private Key and the key from the user
        verify_rs = post(url,params, headers=headers) #Send a post request with the parameters from before to googlde
        verify_rs = verify_rs.json()
        response = verify_rs.get("success", False) #Verify that the response includes the success, if so return True, if not return False
    
        return response 
        
    if (__name__ == "__main__"):
        print("This file is not made fore direct call, please run the main.py")
        exit()