From 24c78727b45b71c704a81315598c1730b10041a9 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Fri, 3 Apr 2026 13:17:39 +0200 Subject: [PATCH] fix method altcha --- README.md | 2 +- tests/async/test_async_altcha.py | 2 ++ tests/sync/test_altcha.py | 2 ++ twocaptcha/async_solver.py | 31 ++++++++++--------------------- twocaptcha/solver.py | 31 +++++++++++-------------------- 5 files changed, 26 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index bd704ce..2e58c39 100644 --- a/README.md +++ b/README.md @@ -533,7 +533,7 @@ Use this method to solve Altcha Captcha. Returns a token. ```python result = solver.altcha(pageurl='https://mysite.com/page/with/altcha', challenge_json='{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}', - # or: challenge_url='https://example.com/altcha-challenge',) + # challenge_url='https://example.com/altcha-challenge',) ``` ## Other methods diff --git a/tests/async/test_async_altcha.py b/tests/async/test_async_altcha.py index 6bbcef5..ffc4a25 100644 --- a/tests/async/test_async_altcha.py +++ b/tests/async/test_async_altcha.py @@ -13,12 +13,14 @@ def test_all_params(self): params = { 'pageurl': 'https://mysite.com/page/with/altcha', 'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}', + 'challenge_url': 'https://example/altcha' } sends = { 'method': 'altcha', 'pageurl': 'https://mysite.com/page/with/altcha', 'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}', + 'challenge_url': 'https://example/altcha' } self.send_return(sends, self.solver.altcha, **params) diff --git a/tests/sync/test_altcha.py b/tests/sync/test_altcha.py index beb3e89..44c14d9 100644 --- a/tests/sync/test_altcha.py +++ b/tests/sync/test_altcha.py @@ -14,12 +14,14 @@ def test_all_params(self): params = { 'pageurl': 'https://mysite.com/page/with/altcha', 'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}', + 'challenge_url': 'https://example/altcha' } sends = { 'method': 'altcha', 'pageurl': 'https://mysite.com/page/with/altcha', 'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}', + 'challenge_url': 'https://example/altcha' } return self.send_return(sends, self.solver.altcha, **params) diff --git a/twocaptcha/async_solver.py b/twocaptcha/async_solver.py index 02ee062..b7d291a 100644 --- a/twocaptcha/async_solver.py +++ b/twocaptcha/async_solver.py @@ -998,40 +998,29 @@ async def yandex_smart(self, sitekey, url, **kwargs): **kwargs) return result - async def altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs): + async def altcha(self, pageurl, **kwargs): '''Wrapper for solving Altcha Captcha. Parameters __________ pageurl : str Full URL of the page where you solve the captcha. - challenge_url : str + challenge_url : str, optional The value of the 'challenge_url' parameter for the 'altcha-widget' element containing the captcha on the page. - You can send either challenge_url or challenge_json parameter, but not two of it simultaneously. - challenge_json : str - The contents of the file from the 'challenge_url' parameter. You can send either challenge_url or challenge_json - parameter, but not two of it simultaneously. + At least one of the parameters 'challenge_url', 'challenge_json' must be passed. + challenge_json : str, optional + The contents of the file from the 'challenge_url' parameter. + At least one of the parameters 'challenge_url', 'challenge_json' must be passed. proxy : dict, optional {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. ''' - if (challenge_url is None) == (challenge_json is None): - raise ValidationException( - 'You must provide exactly one of challenge_url or challenge_json' - ) - - params = { - 'pageurl': pageurl, - 'method': 'altcha', - **kwargs,} - - if challenge_url is not None: - params['challenge_url'] = challenge_url - if challenge_json is not None: - params['challenge_json'] = challenge_json + result = self.solve(pageurl=pageurl, + method='altcha', + **kwargs) - return await self.solve(**params) + return await result async def solve(self, timeout=0, polling_interval=0, **kwargs): '''Sends captcha, receives result. diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index 6a32c56..afa2253 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -1132,39 +1132,30 @@ def yandex_smart(self, sitekey, url, **kwargs): **kwargs) return result - def altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs): + def altcha(self, pageurl, **kwargs): '''Wrapper for solving Altcha Captcha. Parameters __________ pageurl : str Full URL of the page where you solve the captcha. - challenge_url : str + challenge_url : str, optional The value of the 'challenge_url' parameter for the 'altcha-widget' element containing the captcha on the page. - You can send either challenge_url or challenge_json parameter, but not two of it simultaneously. - challenge_json : str - The contents of the file from the 'challenge_url' parameter. You can send either challenge_url or challenge_json - parameter, but not two of it simultaneously. + At least one of the parameters 'challenge_url', 'challenge_json' must be passed. + challenge_json : str, optional + The contents of the file from the 'challenge_url' parameter. + At least one of the parameters 'challenge_url', 'challenge_json' must be passed. proxy : dict, optional {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. ''' - if (challenge_url is None) == (challenge_json is None): - raise ValidationException( - 'You must provide exactly one of challenge_url or challenge_json' - ) - params = { - 'pageurl': pageurl, - 'method': "altcha", - **kwargs, - } - if challenge_url is not None: - params['challenge_url'] = challenge_url - if challenge_json is not None: - params['challenge_json'] = challenge_json + result = self.solve( + pageurl=pageurl, + method="altcha", + **kwargs) - return self.solve(**params) + return result def solve(self, timeout=0, polling_interval=0, **kwargs):