Forked from sameerkumar18/example_flask_googlecaptcha.py
Created
October 2, 2019 18:46
-
-
Save tkhn/e818342c541b9fb4c0b94b4fcb72a9c5 to your computer and use it in GitHub Desktop.
A Simple Python Flask Example for Google Recaptcha (implemented on http://ipusearch.herokuapp.com)
This file contains hidden or 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
| 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