Examples

Using HTTP interface in Python

import captcha
cap = captcha.CaptchaHTTP()
cap.create()
# returns a hash that is used to generate the CAPTCHA image
# e.g. '8TP8DEMLT4'

The following example shows how to insert the CAPTCHA image into the page:

<img src="http://captcha.seznam.cz/captcha.getImage?hash=${captchaHash}">

The following example shows how to insert the CAPTCHA audio file into the page:

<a href="http://captcha.seznam.cz/captcha.getAudio?hash=${captchaHash}">

The checking code is very simple (the values of captchaHash and captchaCode must be sent from a form by the web browser):

import captcha
cap = captcha.CaptchaHTTP()
if not cap.check(captchaHash, captchaCode):
    # Error - code from the image was not entered correctly.
    # Add logic that handles the wrong CAPTCHA code.

Using FRPC interface in Python

The API can be used directly using the XML-RPC (FastRPC) interface. The use is similar to the previous example, you only need to create an CaptchaRCP() object. The RPC interface has the following methods:

captcha.create()
captcha.getImage(string hash)
captcha.getAudio(string hash)
captcha.check(string hash, string code)