-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathsolver.py
executable file
·1245 lines (1045 loc) · 49.5 KB
/
solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import os, sys
import time
import requests
from base64 import b64encode
try:
from .api import ApiClient
except ImportError:
from api import ApiClient
class SolverExceptions(Exception):
pass
class ValidationException(SolverExceptions):
pass
class NetworkException(SolverExceptions):
pass
class ApiException(SolverExceptions):
pass
class TimeoutException(SolverExceptions):
pass
class TwoCaptcha():
"""
Class for interacting with the 2captcha API.
This class provides methods for solving various types of CAPTCHAs, such as image CAPTCHAs, audio CAPTCHAs, reCAPTCHAs,
hCAPTCHAs, and others. It handles sending CAPTCHAs to the 2captcha service and retrieving the solution.
Parameters
__________
API_KEY : str
Your personal API key for accessing the 2captcha API.
soft_id : int, optional
Software ID obtained after publishing in the 2captcha software catalog. Default is 4580.
callback : str, optional
URL of your server to receive the result of the captcha recognition via callback.
It must be registered in your 2captcha account settings. Default is None.
default_timeout : int, optional
The timeout (in seconds) for polling responses for normal CAPTCHAs, excluding reCAPTCHA. Default is 120.
recaptcha_timeout : int, optional
The timeout (in seconds) for polling responses specifically for reCAPTCHAs. Default is 600.
polling_interval : int, optional
The interval (in seconds) between requests to the 2captcha API for retrieving the captcha solution. Default is 10.
api_client : ApiClient
An instance of the ApiClient class to handle API requests.
max_files : int
Maximum number of files that can be sent to the API in one request. Default is 9.
exceptions : SolverExceptions
Custom exceptions for handling API errors.
extendedResponse : bool, optional
If True, enables extended responses from the 2captcha API, which provides more detailed result data. Default is None.
Methods
_______
normal(file, **kwargs)
To bypass a normal captcha (distorted text on an image) use the following method. This method can also be used
to recognize any text in an image.
audio(file, lang, **kwargs)
Use the following method to bypass an audio captcha (mp3 formats only).
text(text, **kwargs)
This method can be used to bypass a captcha that requires answering a question provided in clear text.
recaptcha(sitekey, url, version='v2', enterprise=0, **kwargs)
Use the following method to solve reCAPTCHA V2 or V3 and obtain a token to bypass the protection.
funcaptcha(sitekey, url, **kwargs)
FunCaptcha (Arkoselabs) solving method. Returns a token.
geetest(gt, challenge, url, **kwargs)
Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
hcaptcha(sitekey, url, **kwargs)
Use this method to solve the hCaptcha challenge. Returns a token to bypass the captcha.
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)
Token-based method to solve KeyCaptcha.
capy(sitekey, url, **kwargs)
Token-based method to bypass Capy puzzle captcha.
grid(file, **kwargs)
The grid method was originally called the Old reCAPTCHA V2 method. The method can be used to bypass any type of
captcha where you can apply a grid on an image and click specific grid boxes. Returns numbers of boxes.
canvas(file, **kwargs)
The canvas method can be used when you need to draw a line around an object on an image. Returns a set of points'
coordinates to draw a polygon.
coordinates(file, **kwargs)
The ClickCaptcha method returns the coordinates of points on the captcha image. It can be used if you need to
click on particular points in the image.
rotate(files, **kwargs)
This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha.
Returns the rotation angle.
geetest_v4(captcha_id, url, **kwargs)
Use this method to solve GeeTest v4. Returns the response in JSON.
lemin(captcha_id, div_id, url, **kwargs)
Use this method to solve the Lemin captcha. Returns JSON with an answer containing the following values: answer,
challenge_id.
atb_captcha(app_id, api_server, url, **kwargs)
Use this method to solve atbCaptcha challenge. Returns a token to bypass the captcha.
turnstile(sitekey, url, **kwargs)
Use this method to solve Cloudflare Turnstile. Returns JSON with the token.
amazon_waf(sitekey, iv, context, url, **kwargs)
Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat
mitigation for Amazon AWS. Returns JSON with the token.
mtcaptcha(sitekey, url, **kwargs)
Use this method to solve MTCaptcha and obtain a token to bypass the protection.
friendly_captcha(sitekey, url, **kwargs)
Friendly Captcha solving method. Returns a token.
tencent(app_id, url, **kwargs)
Use this method to solve Cutcaptcha. Returns a token.
cutcaptcha(misery_key, apikey, url, **kwargs)
Use this method to solve Cutcaptcha. Returns the response in JSON.
datadome(captcha_url, pageurl, userAgent, proxy, **kwargs)
Use this method to solve DataDome captcha.
cybersiara(master_url_id, pageurl, userAgent, **kwargs)
Use this method to solve CyberSiARA. Returns a token.
solve(timeout=0, polling_interval=0, **kwargs)
Sends CAPTCHA data and retrieves the result.
balance()
Retrieves the balance of your 2captcha account.
report(id_, correct)
Reports the correctness of a solved CAPTCHA.
"""
def __init__(self,
apiKey,
softId=4580,
callback=None,
defaultTimeout=120,
recaptchaTimeout=600,
pollingInterval=10,
server = '2captcha.com',
extendedResponse=None):
"""
Class constructor for interacting with the 2captcha API.
Parameters
__________
apiKey : str
Your personal API key in your account settings.
softId : int, optional
Your software ID obtained after publishing in 2captcha software catalog - https://2captcha.com/software.
Default: 4580.
callback : str, optional
URL of your web server that receives the captcha recognition result.
The URL should be first registered in pingback - https://2captcha.com/setting/pingback - settings of your account.
Default: None.
defaultTimeout : int, optional
Polling timeout in seconds for all captcha types except reCAPTCHA.
Defines how long the module tries to get the answer from the res.php API endpoint.
Default: 120.
recaptchaTimeout : int, optional
Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from the res.php API endpoint.
Default: 600.
pollingInterval : int, optional
Interval in seconds between requests to the res.php API endpoint. Setting values less than 5 seconds is not recommended.
Default: 10.
server : str, optional
API server. You can set it to rucaptcha.com if your account is registered there.
Default: 2captcha.com.
extendedResponse : bool, optional
Set to True to get the response with additional fields or in more practical format (enables JSON response from
res.php API endpoint). Suitable for hCaptcha, ClickCaptcha, Canvas.
Default: None.
"""
self.API_KEY = apiKey
self.soft_id = softId
self.callback = callback
self.default_timeout = defaultTimeout
self.recaptcha_timeout = recaptchaTimeout
self.polling_interval = pollingInterval
self.api_client = ApiClient(post_url = str(server))
self.max_files = 9
self.exceptions = SolverExceptions
self.extendedResponse = extendedResponse
def normal(self, file, **kwargs):
'''Wrapper for solving a normal captcha (image).
Parameters
__________
file : file
Captcha image file. * required if you submit image as a file (method=post).
body : str
Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
phrase : int, optional
0 - captcha contains one word. 1 - captcha contains two or more words.
Default: 0.
numeric : int, optional
0 - not specified. 1 - captcha contains only numbers. 2 - captcha contains only letters. 3 - captcha
contains only numbers OR only letters. 4 - captcha MUST contain both numbers AND letters.
Default: 0
minLen : int, optional
0 - not specified. 1..20 - minimal number of symbols in captcha.
Default: 0.
maxLen : int, optional
0 - not specified. 1..20 - maximal number of symbols in captcha.
Default: 0.
caseSensitive : int, optional
0 - captcha in not case sensitive. 1 - captcha is case sensitive.
Default: 0.
calc : int, optional
0 - not specified. 1 - captcha requires calculation (e.g. type the result 4 + 8 = ).
Default: 0.
lang : str, optional
Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
hintText : str, optional
Max 140 characters. Encoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
For example: type red symbols only.
hintImg : img, optional
Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
instruction as text with textinstructions.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
'''
method = self.get_method(file)
result = self.solve(**method, **kwargs)
return result
def audio(self, file, lang, **kwargs):
'''Wrapper for solving audio captcha.
Parameters
__________
body : str
Base64 encoded audio file in mp3 format. Max file size: 1 MB.
lang : str
The language of audio record. Supported languages are: "en", "ru", "de", "el", "pt", "fr".
'''
method = "audio"
if not file:
raise ValidationException('File is none')
elif not '.' in file and len(file) > 50:
body = file
elif file.endswith(".mp3") and file.startswith("http"):
response = requests.get(file)
if response.status_code != 200:
raise ValidationException(f'File could not be downloaded from url: {file}')
body = b64encode(response.content).decode('utf-8')
elif file.endswith(".mp3"):
with open(file, "rb") as media:
body = b64encode(media.read()).decode('utf-8')
else:
raise ValidationException('File extension is not .mp3 or it is not a base64 string.')
if not lang or lang not in ("en", "ru", "de", "el", "pt", "fr"):
raise ValidationException(f'Lang not in "en", "ru", "de", "el", "pt", "fr". You send {lang}')
result = self.solve(body=body, method=method, **kwargs)
return result
def text(self, text, **kwargs):
'''Wrapper for solving text captcha.
Parameters
__________
text : str
Max 140 characters. Encoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
For example: type red symbols only.
lang: str, optional
Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
'''
result = self.solve(text=text, method='post', **kwargs)
return result
def recaptcha(self, sitekey, url, version='v2', enterprise=0, **kwargs):
'''Wrapper for solving recaptcha (v2, v3).
Parameters
__________
sitekey : str
Value of sitekey parameter you found on page.
url : str
Full URL of the page where you see the reCAPTCHA.
domain : str, optional
Domain used to load the captcha: google.com or recaptcha.net. Default: google.com.
invisible : int, optional
1 - means that reCAPTCHA is invisible. 0 - normal reCAPTCHA. Default: 0.
version : str, optional
v3 — defines that you're sending a reCAPTCHA V3. Default: v2.
enterprise : str, optional
1 - defines that you're sending reCAPTCHA Enterpise. Default: 0.
action : str, optional
Value of action parameter you found on page. Default: verify.
score : str, only for v3, optional
The score needed for resolution. Currently, it's almost impossible to get token with score higher than 0.3.
Default: 0.4.
data-s : str, only for v2, optional
Value of data-s parameter you found on page. Curenttly applicable for Google Search and other Google services.
cookies : str, only for v2, optional
Your cookies that will be passed to our worker who solve the captha. We also return worker's cookies in the
response if you use json=1. Format: KEY:Value, separator: semicolon, example: KEY1:Value1;KEY2:Value2;
userAgent : str, only for v2, optional
Your userAgent that will be passed to our worker and used to solve the captcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
params = {
'googlekey': sitekey,
'url': url,
'method': 'userrecaptcha',
'version': version,
'enterprise': enterprise,
**kwargs,
}
result = self.solve(timeout=self.recaptcha_timeout, **params)
return result
def funcaptcha(self, sitekey, url, **kwargs):
'''Wrapper for solving funcaptcha.
Parameters
__________
sitekey : str
Value of pk or data-pkey parameter you found on page.
url : str
Full URL of the page where you see the FunCaptcha.
surl : str, optional
Value of surl parameter you found on page.
userAgent: str, optional
Tells us to use your user-agent value.
data[key] : str, optional
Custom data to pass to FunCaptcha. For example: data[blob]=stringValue.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(publickey=sitekey,
url=url,
method='funcaptcha',
**kwargs)
return result
def geetest(self, gt, challenge, url, **kwargs):
'''Wrapper for solving geetest captcha.
Parameters
__________
gt : str
Value of gt parameter you found on target website.
challenge : str
Value of challenge parameter you found on target website.
url : str
Full URL of the page where you see Geetest captcha.
offline : num, optional
In rare cases initGeetest can be called with offline parameter. If the call uses offline: true, set the
value to 1. Default: 0.
new_captcha : num, optional
In rare cases initGeetest can be called with new_captcha parameter. If the call uses new_captcha: true, set
the value to 1. Mostly used with offline parameter.
userAgent : str, optional
Your userAgent that will be passed to our worker and used to solve the captcha.
apiServer : str, optional
Value of api_server parameter you found on target website.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(gt=gt,
challenge=challenge,
url=url,
method='geetest',
**kwargs)
return result
def hcaptcha(self, sitekey, url, **kwargs):
'''Wrapper for solving hcaptcha.
Parameters
__________
sitekey : str
Value of data-sitekey parameter you found on page.
url : str
Full URL of the page where you bypass the captcha.
invisible : num, optional
Use 1 for invisible version of hcaptcha. Currently it is a very rare case.
Default: 0.
data : str, optional
Custom data that is used in some implementations of hCaptcha, mostly with invisible=1. In most cases you see
it as rqdata inside network requests. Format: "data": "rqDataValue".
domain : str, optional
Domain used to load the captcha: hcaptcha.com or js.hcaptcha.com. Default: hcaptcha.com.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(sitekey=sitekey,
url=url,
method='hcaptcha',
**kwargs)
return result
def keycaptcha(self, s_s_c_user_id, s_s_c_session_id,
s_s_c_web_server_sign, s_s_c_web_server_sign2, url,
**kwargs):
'''Wrapper for solving.
Parameters
__________
s_s_c_user_id : str
Value of s_s_c_user_id parameter you found on page.
s_s_c_session_id : str
Value of s_s_c_session_id parameter you found on page.
s_s_c_web_server_sign : str
Value of s_s_c_web_server_sign parameter you found on page.
s_s_c_web_server_sign2 : str
Value of s_s_c_web_server_sign2 parameter you found on page.
url : str
Full URL of the page where you see the KeyCaptcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
params = {
's_s_c_user_id': s_s_c_user_id,
's_s_c_session_id': s_s_c_session_id,
's_s_c_web_server_sign': s_s_c_web_server_sign,
's_s_c_web_server_sign2': s_s_c_web_server_sign2,
'url': url,
'method': 'keycaptcha',
**kwargs,
}
result = self.solve(**params)
return result
def capy(self, sitekey, url, **kwargs):
'''Wrapper for solving capy.
Parameters
__________
sitekey : str
The domain part of script URL you found on page. Default value: https://jp.api.capy.me/.
url : str
Full URL of the page where you see the captcha.
api_server : str, optional
The domain part of script URL you found on page. Default value: https://jp.api.capy.me/.
version : str, optional
The version of captcha task: "puzzle" (assemble a puzzle) or "avatar" (drag an object). Default: puzzle.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(captchakey=sitekey,
url=url,
method='capy',
**kwargs)
return result
def grid(self, file, **kwargs):
'''Wrapper for solving grid captcha (image).
Required:
file : file
Captcha image file. * required if you submit image as a file (method=post).
body : str
Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
hintText : str
Max 140 characters. Encoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select images
with trees. Not required if you're sending instruction as an image with imginstructions.
hintImg : img
Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
instruction as text with textinstructions.
rows : int, optional
Number of rows in reCAPTCHA grid.
cols : itn, optional
Number of columns in reCAPTCHA grid.
previousId : str, optional
Id of your previous request with the same captcha challenge.
canSkip : int, optional
0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's
possible that there's no images matching to the instruction. We'll provide a button "No matching images" to
worker, and you will receive No_matching_images as answer.
Default: 0.
lang: str, optional
Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
method = self.get_method(file)
params = {
'recaptcha': 1,
**method,
**kwargs,
}
result = self.solve(**params)
return result
def canvas(self, file, **kwargs):
'''Wrapper for solving canvas captcha (image).
Parameters
__________
file : file
Captcha image file. * required if you submit image as a file (method=post).
body : str
Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
hintText : str
Max 140 characters. Encoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select
images with trees. Not required if you're sending instruction as an image with imginstructions.
hintImg : img
Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
instruction as text with textinstructions.
canSkip : int, optional
0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's
possible that there's no images matching to the instruction. We'll provide a button "No matching images" to
worker, and you will receive No_matching_images as answer.
Default: 0.
lang : int, optional
0 - not specified. 1 - Cyrillic captcha. 2 - Latin captcha.
Default: 0.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
'''
if not ('hintText' in kwargs or 'hintImg' in kwargs):
raise ValidationException(
'parameters required: hintText and/or hintImg')
method = self.get_method(file)
params = {
'recaptcha': 1,
'canvas': 1,
**method,
**kwargs,
}
result = self.solve(**params)
return result
def coordinates(self, file, **kwargs):
'''Wrapper for solving coordinates captcha (image).
Parameters
__________
file : file
Captcha image file. * required if you submit image as a file (method=post).
body : str
Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
hintText : str
Max 140 characters. Encoding: UTF-8. Text with instruction for solving the captcha. For example: click on
images with ghosts. Not required if the image already contains the instruction.
hintImg : img
Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
instruction as text with textinstructions.
lang : str, optional
Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
'''
method = self.get_method(file)
params = {
'coordinatescaptcha': 1,
**method,
**kwargs,
}
result = self.solve(**params)
return result
def rotate(self, files, **kwargs):
'''Wrapper for solving rotate captcha (image).
Parameters
__________
files : file
Captcha image file. * required if you submit image as a file (method=post).
body : str
Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
angle : int, optional
Angle for one rotation step in degrees. If not defined we'll use the default value for FunCaptcha: 40 degrees.
Default: 40.
lang : str, optional
Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
hintImg : str, optional
Image with instruction for worker to help him to solve captcha correctly.
hintText : str, optional
Text will be shown to worker to help him to to solve captcha correctly.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
if isinstance(files, str):
file = self.get_method(files)['file']
result = self.solve(file=file, method='rotatecaptcha', **kwargs)
return result
elif isinstance(files, dict):
files = list(files.values())
files = self.extract_files(files)
result = self.solve(files=files, method='rotatecaptcha', **kwargs)
return result
def geetest_v4(self, captcha_id, url, **kwargs):
'''Wrapper for solving geetest_v4 captcha.
Parameters
__________
captcha_id : str
Value of captcha_id parameter you found on target website.
url: str
Full URL of the page where you see Geetest captcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(captcha_id=captcha_id,
url=url,
method='geetest_v4',
**kwargs)
return result
def lemin(self, captcha_id, div_id, url, **kwargs):
'''Wrapper for solving Lemin Cropped Captcha.
Parameters
__________
captcha_id : str
Value of captcha_id parameter you found on page.
div_id : str
The id of captcha parent div element.
url : str
Full URL of the page where you see the captcha.
api_server : str, optional
The domain part of script URL you found on page. Default value: https://api.leminnow.com/.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(captcha_id=captcha_id,
div_id=div_id,
url=url,
method='lemin',
**kwargs)
return result
def atb_captcha(self, app_id, api_server, url, **kwargs):
'''Wrapper for solving atbCAPTCHA.
Parameters
__________
app_id : str
The value of appId parameter in the website source code.
api_server : str
The value of apiServer parameter in the website source code.
url : str
The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is
available only for authenticated users.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(app_id=app_id,
api_server=api_server,
url=url,
method='atb_captcha',
**kwargs)
return result
def turnstile(self, sitekey, url, **kwargs):
'''Wrapper for solving Cloudflare Turnstile.
Parameters
__________
sitekey : str
Value of sitekey parameter you found on page.
url : str
Full URL of the page where you see the captcha.
useragent : str
User-Agent of your browser. Must match the User-Agent you use to access the site.
Use only modern browsers released within the last 6 months.
action : str. optional
Value of optional action parameter you found on page, can be defined in data-action attribute or passed
to turnstile.render call.
data : str, optional
The value of cData passed to turnstile.render call. Also can be defined in data-cdata attribute.
pagedata : str, optional
The value of the chlPageData parameter when calling turnstile.render.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(sitekey=sitekey,
url=url,
method='turnstile',
**kwargs)
return result
def amazon_waf(self, sitekey, iv, context, url, **kwargs):
'''Wrapper for solving Amazon WAF.
Parameters
__________
sitekey : str
Value of key parameter you found on the page.
iv : str
Value of iv parameter you found on the page.
context : str
Value of optional context parameter you found on page.
url : str
Full URL of the page where you see the captcha.
challenge_script : str, optional
The source URL of challenge.js script on the page.
captcha_script : str, optional
The source URL of captcha.js script on the page.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(sitekey=sitekey,
iv=iv,
context=context,
url=url,
method='amazon_waf',
**kwargs)
return result
def mtcaptcha(self, sitekey, url, **kwargs):
'''Wrapper for solving MTCaptcha.
Parameters
__________
sitekey : str
The value of sitekey parameter found on the page.
url : str
Full URL of the page where you solve the captcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(sitekey=sitekey,
url=url,
method='mt_captcha',
**kwargs)
return result
def friendly_captcha(self, sitekey, url, **kwargs):
'''Wrapper for solving Friendly Captcha.
Parameters
__________
sitekey : str
The value of data-sitekey attribute of captcha's div element on page.
url : str
Full URL of the page where you solve the captcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(sitekey=sitekey,
url=url,
method='friendly_captcha',
**kwargs)
return result
def tencent(self, app_id, url, **kwargs):
'''Wrapper for solving Tencent captcha.
Parameters
__________
app_id : str
The value of appId parameter in the website source code.
url : str
The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is
available only for authenticated users.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(app_id=app_id,
url=url,
method="tencent",
**kwargs)
return result
def cutcaptcha(self, misery_key, apikey, url, **kwargs):
'''Wrapper for solving Friendly Captcha.
Parameters
__________
misery_key : str
The value of CUTCAPTCHA_MISERY_KEY variable defined on page.
apikey : str
The value of data-apikey attribute of iframe's body. Also, the name of javascript file included on the page.
url : str
Full URL of the page where you solve the captcha.
softId : int, optional
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
spendings of their software users.
callback : str, optional
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
the server. More info here https://2captcha.com/2captcha-api#pingback.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(misery_key=misery_key,
api_key=apikey,
url=url,
method='cutcaptcha',
**kwargs)
return result
def datadome(self, captcha_url, pageurl, userAgent, proxy, **kwargs):
"""Wrapper for solving DataDome Captcha.
Parameters
__________
captcha_url: str
The value of the 'src' parameter for the 'iframe' element containing the captcha on the page.
pageurl: str
Full URL of the page that triggers the captcha when you go to it.
userAgent: str
User-Agent of the browser that will be used by the employee when loading the captcha.
proxy : dict
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
"""
result = self.solve(method='datadome',
captcha_url=captcha_url,
pageurl=pageurl,
userAgent=userAgent,
proxy=proxy,
**kwargs)
return result
def cybersiara(self, master_url_id, pageurl, userAgent, **kwargs):
'''Wrapper for solving CyberSiARA captcha.
Parameters
__________
master_url_id : str
The value of the MasterUrlId parameter from the request to API/CyberSiara/GetCyberSiara.
pageurl : str
Full URL of the page with captcha.
userAgent : str
User-Agent of your browser.
proxy : dict, optional
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
'''
result = self.solve(method='cybersiara',
master_url_id=master_url_id,
pageurl=pageurl,
userAgent=userAgent,
**kwargs)
return result
def solve(self, timeout=0, polling_interval=0, **kwargs):
'''Sends captcha, receives result.
Parameters
__________
timeout : float
polling_interval : int
**kwargs : dict
all captcha params
Returns
result : string
'''