Last active
June 19, 2021 03:53
-
-
Save sleepless-se/0da703f1df894584673d538cd09a5245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import json | |
class Recaptcha(): | |
url = 'https://www.google.com/recaptcha/api/siteverify' | |
# Get secret an public key from https://www.google.com/recaptcha/admin/ | |
secret = 'YOUR_SECRET_KEY' | |
site_key = 'YOUR_SITE_KEY' | |
def __init__(self, DEBUG=False): | |
if DEBUG: | |
self.secret = 'YOUR_LOCAL_SECRET_KEY' | |
self.site_key = 'YOUR_LOCAL_SITE_KEY' | |
def get_results(self, recaptcha_response: str) -> dict: | |
data = { | |
'secret': self.secret, | |
'response': recaptcha_response, | |
} | |
data = urllib.parse.urlencode(data).encode() | |
req = urllib.request.Request(self.url, data=data) | |
response = urllib.request.urlopen(req) | |
return json.loads(response.read().decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Backend setting in Django