@@ -34,6 +34,100 @@ class TimeoutException(SolverExceptions):
3434
3535
3636class TwoCaptcha ():
37+ """
38+ Class for interacting with the 2captcha API.
39+
40+ This class provides methods for solving various types of CAPTCHAs, such as image CAPTCHAs, audio CAPTCHAs, reCAPTCHAs,
41+ hCAPTCHAs, and others. It handles sending CAPTCHAs to the 2captcha service and retrieving the solution.
42+
43+ Parameters
44+ __________
45+ API_KEY : str
46+ Your personal API key for accessing the 2captcha API.
47+ soft_id : int, optional
48+ Software ID obtained after publishing in the 2captcha software catalog. Default is 4580.
49+ callback : str, optional
50+ URL of your server to receive the result of the captcha recognition via callback.
51+ It must be registered in your 2captcha account settings. Default is None.
52+ default_timeout : int, optional
53+ The timeout (in seconds) for polling responses for normal CAPTCHAs, excluding reCAPTCHA. Default is 120.
54+ recaptcha_timeout : int, optional
55+ The timeout (in seconds) for polling responses specifically for reCAPTCHAs. Default is 600.
56+ polling_interval : int, optional
57+ The interval (in seconds) between requests to the 2captcha API for retrieving the captcha solution. Default is 10.
58+ api_client : ApiClient
59+ An instance of the ApiClient class to handle API requests.
60+ max_files : int
61+ Maximum number of files that can be sent to the API in one request. Default is 9.
62+ exceptions : SolverExceptions
63+ Custom exceptions for handling API errors.
64+ extendedResponse : bool, optional
65+ If True, enables extended responses from the 2captcha API, which provides more detailed result data. Default is None.
66+
67+ Methods
68+ _______
69+ normal(file, **kwargs)
70+ To bypass a normal captcha (distorted text on an image) use the following method. This method can also be used
71+ to recognize any text in an image.
72+ audio(file, lang, **kwargs)
73+ Use the following method to bypass an audio captcha (mp3 formats only).
74+ text(text, **kwargs)
75+ This method can be used to bypass a captcha that requires answering a question provided in clear text.
76+ recaptcha(sitekey, url, version='v2', enterprise=0, **kwargs)
77+ Use the following method to solve reCAPTCHA V2 or V3 and obtain a token to bypass the protection.
78+ funcaptcha(sitekey, url, **kwargs)
79+ FunCaptcha (Arkoselabs) solving method. Returns a token.
80+ geetest(gt, challenge, url, **kwargs)
81+ Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
82+ hcaptcha(sitekey, url, **kwargs)
83+ Use this method to solve the hCaptcha challenge. Returns a token to bypass the captcha.
84+ keycaptcha(s_s_c_user_id, s_s_c_session_id, s_s_c_web_server_sign, s_s_c_web_server_sign2, url, **kwargs)
85+ Token-based method to solve KeyCaptcha.
86+ capy(sitekey, url, **kwargs)
87+ Token-based method to bypass Capy puzzle captcha.
88+ grid(file, **kwargs)
89+ The grid method was originally called the Old reCAPTCHA V2 method. The method can be used to bypass any type of
90+ captcha where you can apply a grid on an image and click specific grid boxes. Returns numbers of boxes.
91+ canvas(file, **kwargs)
92+ The canvas method can be used when you need to draw a line around an object on an image. Returns a set of points'
93+ coordinates to draw a polygon.
94+ coordinates(file, **kwargs)
95+ The ClickCaptcha method returns the coordinates of points on the captcha image. It can be used if you need to
96+ click on particular points in the image.
97+ rotate(files, **kwargs)
98+ This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha.
99+ Returns the rotation angle.
100+ geetest_v4(captcha_id, url, **kwargs)
101+ Use this method to solve GeeTest v4. Returns the response in JSON.
102+ lemin(captcha_id, div_id, url, **kwargs)
103+ Use this method to solve the Lemin captcha. Returns JSON with an answer containing the following values: answer,
104+ challenge_id.
105+ atb_captcha(app_id, api_server, url, **kwargs)
106+ Use this method to solve atbCaptcha challenge. Returns a token to bypass the captcha.
107+ turnstile(sitekey, url, **kwargs)
108+ Use this method to solve Cloudflare Turnstile. Returns JSON with the token.
109+ amazon_waf(sitekey, iv, context, url, **kwargs)
110+ Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat
111+ mitigation for Amazon AWS. Returns JSON with the token.
112+ mtcaptcha(sitekey, url, **kwargs)
113+ Use this method to solve MTCaptcha and obtain a token to bypass the protection.
114+ friendly_captcha(sitekey, url, **kwargs)
115+ Friendly Captcha solving method. Returns a token.
116+ tencent(app_id, url, **kwargs)
117+ Use this method to solve Cutcaptcha. Returns a token.
118+ cutcaptcha(misery_key, apikey, url, **kwargs)
119+ Use this method to solve Cutcaptcha. Returns the response in JSON.
120+ datadome(captcha_url, pageurl, userAgent, proxy, **kwargs)
121+ Use this method to solve DataDome captcha.
122+ cybersiara(master_url_id, pageurl, userAgent, **kwargs)
123+ Use this method to solve CyberSiARA. Returns a token.
124+ solve(timeout=0, polling_interval=0, **kwargs)
125+ Sends CAPTCHA data and retrieves the result.
126+ balance()
127+ Retrieves the balance of your 2captcha account.
128+ report(id_, correct)
129+ Reports the correctness of a solved CAPTCHA.
130+ """
37131 def __init__ (self ,
38132 apiKey ,
39133 softId = 4580 ,
@@ -43,7 +137,38 @@ def __init__(self,
43137 pollingInterval = 10 ,
44138 server = '2captcha.com' ,
45139 extendedResponse = None ):
140+ """
141+ Class constructor for interacting with the 2captcha API.
46142
143+ Parameters
144+ __________
145+ apiKey : str
146+ Your personal API key in your account settings.
147+ softId : int, optional
148+ Your software ID obtained after publishing in 2captcha software catalog - https://2captcha.com/software.
149+ Default: 4580.
150+ callback : str, optional
151+ URL of your web server that receives the captcha recognition result.
152+ The URL should be first registered in pingback - https://2captcha.com/setting/pingback - settings of your account.
153+ Default: None.
154+ defaultTimeout : int, optional
155+ Polling timeout in seconds for all captcha types except reCAPTCHA.
156+ Defines how long the module tries to get the answer from the res.php API endpoint.
157+ Default: 120.
158+ recaptchaTimeout : int, optional
159+ Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from the res.php API endpoint.
160+ Default: 600.
161+ pollingInterval : int, optional
162+ Interval in seconds between requests to the res.php API endpoint. Setting values less than 5 seconds is not recommended.
163+ Default: 10.
164+ server : str, optional
165+ API server. You can set it to rucaptcha.com if your account is registered there.
166+ Default: 2captcha.com.
167+ extendedResponse : bool, optional
168+ Set to True to get the response with additional fields or in more practical format (enables JSON response from
169+ res.php API endpoint). Suitable for hCaptcha, ClickCaptcha, Canvas.
170+ Default: None.
171+ """
47172 self .API_KEY = apiKey
48173 self .soft_id = softId
49174 self .callback = callback
@@ -86,7 +211,7 @@ def normal(self, file, **kwargs):
86211 lang : str, optional
87212 Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
88213 hintText : str, optional
89- Max 140 characters. Endcoding : UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
214+ Max 140 characters. Encoding : UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
90215 For example: type red symbols only.
91216 hintImg : img, optional
92217 Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
@@ -143,7 +268,7 @@ def text(self, text, **kwargs):
143268 Parameters
144269 __________
145270 text : str
146- Max 140 characters. Endcoding : UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
271+ Max 140 characters. Encoding : UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
147272 For example: type red symbols only.
148273 lang: str, optional
149274 Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
@@ -162,7 +287,7 @@ def recaptcha(self, sitekey, url, version='v2', enterprise=0, **kwargs):
162287 '''Wrapper for solving recaptcha (v2, v3).
163288
164289 Parameters
165- _______________
290+ __________
166291 sitekey : str
167292 Value of sitekey parameter you found on page.
168293 url : str
@@ -224,7 +349,7 @@ def funcaptcha(self, sitekey, url, **kwargs):
224349 Tells us to use your user-agent value.
225350 data[key] : str, optional
226351 Custom data to pass to FunCaptcha. For example: data[blob]=stringValue.
227- softId : str , optional
352+ softId : int , optional
228353 ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
229354 spendings of their software users.
230355 callback : str, optional
@@ -243,7 +368,7 @@ def funcaptcha(self, sitekey, url, **kwargs):
243368 def geetest (self , gt , challenge , url , ** kwargs ):
244369 '''Wrapper for solving geetest captcha.
245370
246- Parameters:
371+ Parameters
247372 __________
248373 gt : str
249374 Value of gt parameter you found on target website.
@@ -390,7 +515,7 @@ def grid(self, file, **kwargs):
390515 body : str
391516 Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
392517 hintText : str
393- Max 140 characters. Endcoding : UTF-8. Text with instruction for solving reCAPTCHA. For example: select images
518+ Max 140 characters. Encoding : UTF-8. Text with instruction for solving reCAPTCHA. For example: select images
394519 with trees. Not required if you're sending instruction as an image with imginstructions.
395520 hintImg : img
396521 Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
@@ -447,7 +572,7 @@ def canvas(self, file, **kwargs):
447572 body : str
448573 Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
449574 hintText : str
450- Max 140 characters. Endcoding : UTF-8. Text with instruction for solving reCAPTCHA. For example: select
575+ Max 140 characters. Encoding : UTF-8. Text with instruction for solving reCAPTCHA. For example: select
451576 images with trees. Not required if you're sending instruction as an image with imginstructions.
452577 hintImg : img
453578 Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
@@ -494,7 +619,7 @@ def coordinates(self, file, **kwargs):
494619 body : str
495620 Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
496621 hintText : str
497- Max 140 characters. Endcoding : UTF-8. Text with instruction for solving the captcha. For example: click on
622+ Max 140 characters. Encoding : UTF-8. Text with instruction for solving the captcha. For example: click on
498623 images with ghosts. Not required if the image already contains the instruction.
499624 hintImg : img
500625 Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
@@ -973,7 +1098,7 @@ def send(self, **kwargs):
9731098 """This method can be used for manual captcha submission
9741099
9751100 Parameters
976- _________
1101+ __________
9771102 method : str
9781103 The name of the method must be found in the documentation https://2captcha.com/2captcha-api
9791104 kwargs: dict
0 commit comments