Skip to main content

Client library for solve captchas with Anticaptcha.com support.

Project description

https://travis-ci.org/ad-m/python-anticaptcha.svg?branch=master Python package Join the chat at https://gitter.im/python-anticaptcha/Lobby Python compatibility

Client library for solve captchas with Anticaptcha.com support. The library supports both Python 2.7 and Python 3.

The library is cyclically and automatically tested for proper operation. We are constantly making the best efforts for its effective operation.

In case of any problems with integration - read the documentation, create an issue, use Gitter or contact privately.

Getting Started

Install as standard Python package using:

pip install python-anticaptcha

Usage

To use this library do you need Anticaptcha.com API key.

Solve recaptcha

Example snippet for Recaptcha:

from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask

api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'  # grab from site
url = 'https://www.google.com/recaptcha/api2/demo'

client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
job.join()
print job.get_solution_response()

The full integration example is available in file examples/recaptcha.py.

Solve text captcha

Example snippet for text captcha:

from python_anticaptcha import AnticaptchaClient, ImageToTextTask

api_key = '174faff8fbc769e94a5862391ecfd010'
captcha_fp = open('examples/captcha_ms.jpeg', 'rb')
client = AnticaptchaClient(api_key)
task = ImageToTextTask(captcha_fp)
job = client.createTask(task)
job.join()
print job.get_captcha_text()

Solve funcaptcha

Example snippet for funcaptcha:

from python_anticaptcha import AnticaptchaClient, FunCaptchaTask, Proxy
UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 ' \
     '(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'

api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = 'DE0B0BB7-1EE4-4D70-1853-31B835D4506B'  # grab from site
url = 'https://www.google.com/recaptcha/api2/demo'
proxy = Proxy.parse_url("socks5://login:password@123.123.123.123")

client = AnticaptchaClient(api_key)
task = FunCaptchaTask(url, site_key, proxy=proxy, user_agent=user_agent)
job = client.createTask(task)
job.join()
print job.get_token_response()

Report incorrect image

Example snippet for reporting an incorrect image task:

from python_anticaptcha import AnticaptchaClient, ImageToTextTask

api_key = '174faff8fbc769e94a5862391ecfd010'
captcha_fp = open('examples/captcha_ms.jpeg', 'rb')
client = AnticaptchaClient(api_key)
task = ImageToTextTask(captcha_fp)
job = client.createTask(task)
job.join()
print job.get_captcha_text()
job.report_incorrect()

Custom tasks

There is support for your own (captcha) forms. It allows you to analyze any data in various ways, eg. classify offensive image, count elements on the image, etc. The scope of the data, the form to describe them, you specify yourself.

For details, go to ‘Custom fields’ section in the documentation.

Setup proxy

The library is not responsible for managing the proxy server. However, we point to the possibility of simply launching such a server by:

pip install mitmproxy
mitmweb -p 9190 -b 0.0.0.0 --ignore '.' --socks

Next to in your application use something like:

proxy = Proxy.parse_url("socks5://123.123.123.123:9190")

We recommend entering IP-based access control for incoming addresses to proxy. IP address required by Anticaptcha.com is:

69.65.41.21
209.212.146.168

Error handling

In the event of an application error, the AnticaptchaException exception is thrown. To handle the exception, do the following:

from python_anticaptcha import AnticatpchaException, ImageToTextTask

try:
    # any actions
except AnticatpchaException as e:
    if e.error_code == 'ERROR_ZERO_BALANCE':
        notify_about_no_funds(e.error_id, e.error_code, e.error_description)
    else:
        raise

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Adam Dobrawy - Initial work - ad-m

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

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-anticaptcha-0.3.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

python_anticaptcha-0.3.1-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-anticaptcha-0.3.1.tar.gz.

File metadata

File hashes

Hashes for python-anticaptcha-0.3.1.tar.gz
Algorithm Hash digest
SHA256 65ef0b29219032b8f92b8f7eb546d6848d111a457d17c587db6fc516c6f3691a
MD5 962ccd2285170e3f0d5b55d12d7017c4
BLAKE2b-256 cc9fe1c4966e8b2d17bf58269b89ad44a2cc968aa7a65ba045122ee57b69de5a

See more details on using hashes here.

Provenance

File details

Details for the file python_anticaptcha-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_anticaptcha-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 70413d8b73823156d1816eb7592bf8a639f2b2f81f68ffd1e1c1679d359478c5
MD5 c0a10b5dac236256c0a004cbbacf5b77
BLAKE2b-256 01c0410163fcb9ea0d8878338d8d2c2b0cf60301ed2ffc021f14ec1a9631a793

See more details on using hashes here.

Provenance

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