Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions flask_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
except ImportError as ex:
print("Missing dependencies")

from google.appengine.api import urlfetch
import urllib
import json

class ReCaptcha(object):

VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify"
Expand Down Expand Up @@ -58,7 +62,18 @@ def verify(self, response=None, remote_ip=None):
"response": response or request.form.get('g-recaptcha-response'),
"remoteip": remote_ip or request.environ.get('REMOTE_ADDR')
}
form_data = urllib.urlencode(data)


r = requests.get(self.VERIFY_URL, params=data)
return r.json()["success"] if r.status_code == 200 else False
result = urlfetch.fetch(url=self.VERIFY_URL,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
#r = requests.get(self.VERIFY_URL, params=data)
if result.status_code == 200:
result_obj = json.loads(result.content)

return result_obj["success"]
else:
return False
return True