Skip to content

Instantly share code, notes, and snippets.

@sameerkumar18
Created May 20, 2017 07:04
Show Gist options
  • Save sameerkumar18/36ee1ee98ae60eb32bffb1b4fc77bbae to your computer and use it in GitHub Desktop.
Save sameerkumar18/36ee1ee98ae60eb32bffb1b4fc77bbae to your computer and use it in GitHub Desktop.
A Simple Python Flask Example for Google Recaptcha (implemented on http://ipusearch.herokuapp.com)
RECAPTCHA_PUBLIC_KEY = '<public key>'
RECAPTCHA_PRIVATE_KEY = '<private key>'
def checkRecaptcha(response, secretkey):
url = 'https://www.google.com/recaptcha/api/siteverify?'
url = url + 'secret=' + str(secretkey)
url = url + '&response=' +str(response)
jsonobj = json.loads(urllib2.urlopen(url).read())
print jsonobj['success']
if jsonobj['success']:
print jsonobj['success']
return True
else:
return False
@app.route('/bca/2016',methods=['GET','POST'])
def search_bca_2016():
if request.method == 'POST':
response = request.form.get('g-recaptcha-response')
if checkRecaptcha(response, RECAPTCHA_PRIVATE_KEY):
msg = 'You are human.'
print msg
else:
msg = 'You are bot.'
print msg
return render_template('search.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment