Package: 2captcha-python
Python Module for 2Captcha APIThe easiest way to quickly integrate2Captchacaptcha solving service into your code to automate solving of any types of captcha.Python Module for 2Captcha APIInstallationConfigurationTwoCaptcha instance optionsSolve captchaCaptcha optionsNormal CaptchaAudio CaptchaText CaptchaReCaptcha v2ReCaptcha v3FunCaptchaGeeTesthCaptchaGeeTest v4Lemin Cropped CaptchaCloudflare TurnstileAmazon WAFKeyCaptchaCapyGridCanvasClickCaptchaRotateOther methodssend / getResultbalancereportError handlingProxiesAsync callsInstallationThis package can be installed with Pip:pip3 install 2captcha-pythonConfigurationTwoCaptcha instance can be created like this:fromtwocaptchaimportTwoCaptchasolver=TwoCaptcha('YOUR_API_KEY')Also there are few options that can be configured:config={'server':'2captcha.com','apiKey':'YOUR_API_KEY','softId':123,'callback':'https://your.site/result-receiver','defaultTimeout':120,'recaptchaTimeout':600,'pollingInterval':10,}solver=TwoCaptcha(**config)TwoCaptcha instance optionsOptionDefault valueDescriptionserver2captcha.comAPI server. You can set it torucaptcha.comif your account is registered theresoftId-your software ID obtained after publishing in2captcha sofware catalogcallback-URL of your web-sever that receives the captcha recognition result. The URl should be first registered inpingback settingsof your accountdefaultTimeout120Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer fromres.phpAPI endpointrecaptchaTimeout600Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer fromres.phpAPI endpointpollingInterval10Interval in seconds between requests tores.phpAPI endpoint, setting values less than 5 seconds is not recommendedIMPORTANT:oncecallbackis defined forTwoCaptchainstance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL.
To get the answer manually usegetResult methodSolve captchaWhen you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.Captcha optionsOptionDefault ValueDescriptionnumeric0Defines if captcha contains numeric or other symbolssee more info in the API docsminLen0minimal answer lenghtmaxLen0maximum answer lengthphrase0defines if the answer contains multiple words or notcaseSensitive0defines if the answer is case sensitivecalc0defines captcha requires calculationlang-defines the captcha language, see thelist of supported languageshintImg-an image with hint shown to workers with the captchahintText-hint or task text shown to workers with the captchaBelow you can find basic examples for every captcha type. Check outexamples directoryto find more examples with all available options.Normal CaptchaTo bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.result=solver.normal('path/to/captcha.jpg',param1=...,...)# ORresult=solver.normal('https://site-with-captcha.com/path/to/captcha.jpg',param1=...,...)Audio CaptchaTo bypass an audio captcha (mp3 formats only) use the following method.
You must provife the language aslang = 'en'. Supported languages are "en", "ru", "de", "el", "pt".result=solver.audio('path/to/captcha.mp3',lang='lang',param1=...,...)# ORresult=solver.audio('https://site-with-captcha.com/path/to/captcha.mp3',lang='lang',param1=...,...)Text CaptchaThis method can be used to bypass a captcha that requires to answer a question provided in clear text.result=solver.text('If tomorrow is Saturday, what day is today?',param1=...,...)ReCaptcha v2Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection.result=solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',url='https://mysite.com/page/with/recaptcha',param1=...,...)ReCaptcha v3This method provides ReCaptcha V3 solver and returns a token.result=solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',url='https://mysite.com/page/with/recaptcha',version='v3',param1=...,...)FunCaptchaFunCaptcha (Arkoselabs) solving method. Returns a token.result=solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',url='https://mysite.com/page/with/funcaptcha',param1=...,...)GeeTestMethod to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.result=solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e',challenge='12345678abc90123d45678ef90123a456b',url='https://www.site.com/page/',param1=...,...)hCaptchaUse this method to solve hCaptcha challenge. Returns a token to bypass captcha.result=solver.hcaptcha(sitekey='10000000-ffff-ffff-ffff-000000000001',url='https://www.site.com/page/',param1=...,...)GeeTest v4Use this method to solve GeeTest v4. Returns the response in JSON.result=solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',url='https://www.site.com/page/',param1=...,...)Lemin Cropped CaptchaUse this method to solve hCaptcha challenge. Returns JSON with answer containing the following values: answer, challenge_id.result=solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',div_id='lemin-cropped-captcha',url='https://www.site.com/page/',param1=...,...)Cloudflare TurnstileUse this method to solve Cloudflare Turnstile. Returns JSON with the token.result=solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',url='http://mysite.com/',data='foo',pagedata='bar',action='challenge',useragent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36')Amazon WAFUse 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.result=solver.amazon_waf(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',iv='CgAHbCe2GgAAAAAj',context='9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc='url='https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest'param1=...,...)KeyCaptchaToken-based method to solve KeyCaptcha.result=solver.keycaptcha(s_s_c_user_id=10,s_s_c_session_id='493e52c37c10c2bcdf4a00cbc9ccd1e8',s_s_c_web_server_sign='9006dc725760858e4c0715b835472f22-pz-',s_s_c_web_server_sign2='2ca3abe86d90c6142d5571db98af6714',url='https://www.keycaptcha.ru/demo-magnetic/',param1=...,...)CapyToken-based method to bypass Capy puzzle captcha.result=solver.capy(sitekey='PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',url='http://mysite.com/',api_server='https://jp.api.capy.me/',param1=...,...)GridGrid method is originally called Old ReCaptcha V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.result=solver.grid('path/to/captcha.jpg',param1=...,...)CanvasCanvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.result=solver.canvas('path/to/captcha.jpg',param1=...,...)ClickCaptchaClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.result=solver.coordinates('path/to/captcha.jpg',param1=...,...)RotateThis method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.result=solver.rotate('path/to/captcha.jpg',param1=...,...)Other methodssend / getResultThese methods can be used for manual captcha submission and answer polling.importtime.....id=solver.send(file='path/to/captcha.jpg')time.sleep(20)code=solver.get_result(id)balanceUse this method to get your account's balancebalance=solver.balance()reportUse this method to report good or bad captcha answer.solver.report(id,True)# captcha solved correctlysolver.report(id,False)# captcha solved incorrectlyError handlingIn case of an error, the captcha solver throws an exception. It's important to properly handle these cases. We recommend usingtry exceptto handle exceptions.try:result=solver.text('If tomorrow is Saturday, what day is today?')exceptValidationExceptionase:# invalid parameters passedprint(e)exceptNetworkExceptionase:# network error occurredprint(e)exceptApiExceptionase:# api respond with errorprint(e)exceptTimeoutExceptionase:# captcha is not solved so farprint(e)ProxiesYou can pass your proxy as an additional argument for methods: recaptcha, funcaptcha and geetest. The proxy will be forwarded to the API to solve the captcha.proxy={'type':'HTTPS','uri':'login:password@IP_address:PORT'}Async callsYou can also make async calls withasyncio, for example:importasyncioimportconcurrent.futuresfromtwocaptchaimportTwoCaptchacaptcha_result=awaitcaptchaSolver(image)asyncdefcaptchaSolver(image):loop=asyncio.get_running_loop()withconcurrent.future.ThreadPoolExecutor()aspool:result=awaitloop.run_in_executor(pool,lambda:TwoCaptcha(API_KEY).normal(image))returnresult