Skip to main content

Python module for reCAPTCHA service.

Project description

reCAPTCHA is a free CAPTCHA service that protects your site against spam, malicious registrations and other forms of attacks where computers try to disguise themselves as a human.

python-reCAPTCHA is a Python 3.x module, that provides an easy way to interact with the reCAPTCHA API.

Installation

$ pip install python-reCAPTCHA

or

$ git clone https://github.com/rbika/python-reCAPTCHA.git
$ cd python-reCAPTCHA
$ python setup.py install
$ cd .. && rm -rf python-reCAPTCHA

Usage

To use reCAPTCHA, you need to sign up for API keys for your site.

Once you’ve signed up for API keys, adding reCAPTCHA to your site consists of two steps.

1. Displaying the reCAPTCHA Widget

Generate the widget HTML by calling the generate_html function.

>>> from recaptcha.captcha import generate_html
>>>
>>> public_key = "your_public_key"
>>> recaptcha_html = generate_html(public_key)
>>>
>>> print(recaptcha_html)
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=your_public_key"></script><noscript><iframe src="http://www.google.com/recaptcha/api/api/noscript?k=your_public_key"height="300" width="500" frameborder="0"></iframe><br><textarea name="recaptcha_challenge_field"rows="3" cols="40"></textarea><input type="hidden" name="recaptcha_response_field"value="manual_challenge"></noscript>

Place the generated HTML inside your form. If you are working with Django por example, your form will looks like this:

<form action="">
    {% autoscape on %}recaptcha_html{% endautoescape %}
    <input type="submit" value="Submit">
</form>

2. Verifying user’s anwser

After the user submit the anwser, you should get the required paramenters and call the verify function. Again, a Django’s example.

>>> from recaptcha.captcha import verify
>>>
>>> private_key = "your_private_key"
>>> remote_ip = request.META['REMOTE_ADDR']
>>> challenge = request.POST.get('recaptcha_challenge_field', '')
>>> response = request.POST.get('recaptcha_response_field', '')
>>>
>>> result = verify(private_key, remote_ip, challenge, response)
>>>
>>> print(result)
{'success': False, 'error': 'incorrect-captcha-sol'}

Documentation

Documentation will be available soon.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-reCAPTCHA-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file python-reCAPTCHA-0.1.0.tar.gz.

File metadata

File hashes

Hashes for python-reCAPTCHA-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4cf2d36413c26fcc611acca1e0b18daf6dc8f4ebfc8945ab5948cecbbe16aba7
MD5 82dc793aea376829fc5e3204ec9ddd99
BLAKE2b-256 036553de4b4e64da860b2856b9622e464620658fe950ef76aef9fd8b7f7007dd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page