Welcome to python-anticaptcha’s documentation!¶
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.
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
.
If you only process few page many times to increase reliability, you can specify
whether the captcha is visible or not. This parameter is not required, as is the
system detects invisible sitekeys automatically, and needs several recursive
measures for automated training and analysis. For provide that pass
is_invisible
parameter to NoCaptchaTaskProxylessTask
or NoCaptchaTask
eg.:
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = '6Lc-0DYUAAAAAOPM3RGobCfKjIE5STmzvZfHbbNx' # grab from site
url = 'https://losangeles.craigslist.org/lac/kid/d/housekeeper-sitting-pet-care/6720136191.html'
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key, is_invisible=True)
job = client.createTask(task)
job.join()
print job.get_solution_response()
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()
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
API¶
Base¶
- class
python_anticaptcha.base.
AnticaptchaClient
(client_key, language_pool='en', host='api.anti-captcha.com', use_ssl=True)[source]¶
APP_STAT_URL
= '/getAppStats'¶
BALANCE_URL
= '/getBalance'¶
CREATE_TASK_URL
= '/createTask'¶
REPORT_IMAGE_URL
= '/reportIncorrectImageCaptcha'¶
REPORT_RECAPTCHA_URL
= '/reportIncorrectRecaptcha'¶
SOFT_ID
= 847¶
TASK_RESULT_URL
= '/getTaskResult'¶
client_ip
¶
client_key
= None¶
language_pool
= 'en'¶
response_timeout
= 5¶
Exceptions¶
Tasks¶
- class
python_anticaptcha.tasks.
AntiGateTaskProxyless
(website_url, template_name, variables, *args, **kwargs)[source]¶
templateName
= None¶
type
= 'AntiGateTask'¶
variables
= None¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
FunCaptchaProxylessTask
(website_url, website_key, subdomain=None, data=None, *args, **kwargs)[source]¶
data
= None¶
funcaptchaApiJSSubdomain
= None¶
type
= 'FunCaptchaTaskProxyless'¶
websiteKey
= None¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
GeeTestTaskProxyless
(website_url, gt, challenge, subdomain=None, lib=None, *args, **kwargs)[source]¶
challenge
= None¶
geetestApiServerSubdomain
= None¶
geetestGetLib
= None¶
gt
= None¶
type
= 'GeeTestTaskProxyless'¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
HCaptchaTaskProxyless
(website_url, website_key, *args, **kwargs)[source]¶
type
= 'HCaptchaTaskProxyless'¶
websiteKey
= None¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
ImageToTextTask
(fp, phrase=None, case=None, numeric=None, math=None, min_length=None, max_length=None, comment=None, website_url=None, *args, **kwargs)[source]¶
case
= None¶
comment
= None¶
fp
= None¶
math
= None¶
maxLength
= None¶
minLength
= None¶
numeric
= None¶
phrase
= None¶
type
= 'ImageToTextTask'¶
websiteUrl
= None¶
- class
python_anticaptcha.tasks.
NoCaptchaTaskProxylessTask
(website_url, website_key, website_s_token=None, is_invisible=None, recaptcha_data_s_value=None, *args, **kwargs)[source]¶
recaptchaDataSValue
= None¶
type
= 'NoCaptchaTaskProxyless'¶
websiteKey
= None¶
websiteSToken
= None¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
RecaptchaV2EnterpriseTask
(*args, **kwargs)[source]¶
type
= 'RecaptchaV2EnterpriseTask'¶
- class
python_anticaptcha.tasks.
RecaptchaV2EnterpriseTaskProxyless
(website_url, website_key, enterprise_payload, api_domain, *args, **kwargs)[source]¶
apiDomain
= None¶
enterprisePayload
= None¶
type
= 'RecaptchaV2EnterpriseTaskProxyless'¶
websiteKey
= None¶
websiteURL
= None¶
- class
python_anticaptcha.tasks.
RecaptchaV2TaskProxyless
(website_url, website_key, website_s_token=None, is_invisible=None, recaptcha_data_s_value=None, *args, **kwargs)[source]¶
type
= 'RecaptchaV2TaskProxyless'¶
Changelog¶
1.0.0 - 2022-03-28¶
Added¶
- Add new tasks:
AntiGateTask
andAntiGateTaskProxyless
RecaptchaV2EnterpriseTask
andRecaptchaV2EnterpriseTaskProxyless
GeeTestTask
andGeeTestTaskProxyless
RecaptchaV2Task
(alias ofNoCaptchaTask
) andRecaptchaV2TaskProxyless
(alias ofNoCaptchaTaskProxyless
)
- Add example for
AntiGateTaskProxyless
- Add optional parameters
comment
,websiteUrl
toImageToTextTask
- Add optional parameter
funcaptchaApiJSSubdomain
,data
toFunCaptchaTask*
- Add optional parameter
isEnterprise
toRecaptchaV3Task*
Removed¶
- Drop tasks unsupported upstream:
CustomCaptchaTask
,SquareNetTask
Changed¶
- Internal refactor to extract
UserAgentMixin
,CookieMixin
- Use nose2 for tests
0.7.1 - 2020-07-17¶
Added¶
- Added examples for proxy mode including hcaptcha_request_proxy
Changed¶
- Fix inheritance of FunCaptchaTask
- Added FunCaptchaTask to e2e tests
0.7.0 - 2020-06-08¶
Added¶
Added parameter recaptchaDataSValue in NoCaptchaTask*
Thanks to this change added support for additional “data-s” used by some custom ReCaptcha deployments, which is in fact a one-time token and must be grabbed every time you want to solve a Recaptcha. <div class=”g-recaptcha” data-sitekey=”some sitekey” data-s=”THIS_TOKEN”></div>
Changed¶
- Fixed deprecated method report_incorrect. You should currently use report_incorrect_image instead already.
0.6.0 - 2020-04-13¶
Added¶
- Added custom timeout for
createTaskSmee
. Use asclient.createTaskSmee(task, timeout=5*60)
. Default timeout is 5 minutes. - Added
squarenet_validator
for usage with thread pool for concurrent execution
Changed¶
- Default 5 seconds timeout apply to all API request.
0.5.0 - 2020-03-30¶
Added¶
- Added
HCaptchaTaskProxyless
andHCaptchaTask
for support hCaptcha . Seeexamples/hcaptcha_request.py
for detailed usage example. - Added
SquareNetTask
. Seeexamples/squarenet.py
for detailed usage example. - Added
Job.report_incorrect_recaptcha
andJob.report_incorrect_image
.
Changed¶
- Exposed
FunCaptchaProxylessTask
aspython_anticaptcha.FunCaptchaProxylessTask
- Exposed
CustomCaptchaTask
aspython_anticaptcha.CustomCaptchaTask
- Formated code via Black
- Move constant monitoring to GitHub Actions
- Deprecated
Job.report_incorrect
. Usereport_incorrect_image
instead.
0.4.2 - 2019-10-27¶
Added¶
- Added example
remote_image.py
Changed¶
- Switch CI from TravisCI to GitHub Actions
- Automate PyPI releases
- Use
use_scm_version
for versioning - Drop
use_2to3
insetup.py
0.4.1 - 2019-07-09¶
Added¶
- Added
python_anticaptcha.__version__
to provide version signature (see PEP396)
Changed¶
python_anticaptcha.AnticaptchaClient.createTaskSmee
use shared session & keep connection.
0.4.0 - 2019-06-28¶
Added¶
- Added
python_anticaptcha.AnticaptchaClient.createTaskSmee
to receive responses without polling - The method, which is based on the callback result of captcha / task factory to Smee.io, which immediately transfers it to library. Allows to significantly shorten the waiting time for a response and to reduce load the network connection. The method is in beta and the way it works may change. All comments are welcome.
- Added
- Recaptcha V3 is now officially supported by Anti-Captcha. Added
python_anticaptcha.RecaptchaV3TaskProxyless
.
Development¶
The project is open-source.
Changes are managed through GitHub. Pull requests are particularly welcome.
All changes are automatically tested using TravisCI.
New release¶
Follow these steps to publish the new release:
- update changelog - use any text editor
- bump version - use
`bumpversion {major,minor,patch}`
- build package - use
`python setup.py sdist bdist_wheel --universal`
- upload release to PyPI - use
`twine upload dist/*`
- push changes to GitHub -
`git push origin && git push --tags`