Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/async/test_async_altcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/sync/test_altcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 10 additions & 21 deletions twocaptcha/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 11 additions & 20 deletions twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down