Skip to content

Commit 4a107fa

Browse files
authored
fix method altcha (#139)
1 parent 1da0179 commit 4a107fa

5 files changed

Lines changed: 26 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ Use this method to solve Altcha Captcha. Returns a token.
533533
```python
534534
result = solver.altcha(pageurl='https://mysite.com/page/with/altcha',
535535
challenge_json='{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}',
536-
# or: challenge_url='https://example.com/altcha-challenge',)
536+
# challenge_url='https://example.com/altcha-challenge',)
537537
```
538538

539539
## Other methods

tests/async/test_async_altcha.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ def test_all_params(self):
1313
params = {
1414
'pageurl': 'https://mysite.com/page/with/altcha',
1515
'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}',
16+
'challenge_url': 'https://example/altcha'
1617
}
1718

1819
sends = {
1920
'method': 'altcha',
2021
'pageurl': 'https://mysite.com/page/with/altcha',
2122
'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}',
23+
'challenge_url': 'https://example/altcha'
2224
}
2325

2426
self.send_return(sends, self.solver.altcha, **params)

tests/sync/test_altcha.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ def test_all_params(self):
1414
params = {
1515
'pageurl': 'https://mysite.com/page/with/altcha',
1616
'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}',
17+
'challenge_url': 'https://example/altcha'
1718
}
1819

1920
sends = {
2021
'method': 'altcha',
2122
'pageurl': 'https://mysite.com/page/with/altcha',
2223
'challenge_json': '{"algorithm":"SHA-256","challenge":"a4c9d8e7f1b23a6c...",..."signature":"7b3e2a9d5c8f1046e2d91c3a..."}',
24+
'challenge_url': 'https://example/altcha'
2325
}
2426

2527
return self.send_return(sends, self.solver.altcha, **params)

twocaptcha/async_solver.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -998,40 +998,29 @@ async def yandex_smart(self, sitekey, url, **kwargs):
998998
**kwargs)
999999
return result
10001000

1001-
async def altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs):
1001+
async def altcha(self, pageurl, **kwargs):
10021002
'''Wrapper for solving Altcha Captcha.
10031003
10041004
Parameters
10051005
__________
10061006
pageurl : str
10071007
Full URL of the page where you solve the captcha.
1008-
challenge_url : str
1008+
challenge_url : str, optional
10091009
The value of the 'challenge_url' parameter for the 'altcha-widget' element containing the captcha on the page.
1010-
You can send either challenge_url or challenge_json parameter, but not two of it simultaneously.
1011-
challenge_json : str
1012-
The contents of the file from the 'challenge_url' parameter. You can send either challenge_url or challenge_json
1013-
parameter, but not two of it simultaneously.
1010+
At least one of the parameters 'challenge_url', 'challenge_json' must be passed.
1011+
challenge_json : str, optional
1012+
The contents of the file from the 'challenge_url' parameter.
1013+
At least one of the parameters 'challenge_url', 'challenge_json' must be passed.
10141014
proxy : dict, optional
10151015
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
10161016
10171017
'''
10181018

1019-
if (challenge_url is None) == (challenge_json is None):
1020-
raise ValidationException(
1021-
'You must provide exactly one of challenge_url or challenge_json'
1022-
)
1023-
1024-
params = {
1025-
'pageurl': pageurl,
1026-
'method': 'altcha',
1027-
**kwargs,}
1028-
1029-
if challenge_url is not None:
1030-
params['challenge_url'] = challenge_url
1031-
if challenge_json is not None:
1032-
params['challenge_json'] = challenge_json
1019+
result = self.solve(pageurl=pageurl,
1020+
method='altcha',
1021+
**kwargs)
10331022

1034-
return await self.solve(**params)
1023+
return await result
10351024

10361025
async def solve(self, timeout=0, polling_interval=0, **kwargs):
10371026
'''Sends captcha, receives result.

twocaptcha/solver.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,39 +1132,30 @@ def yandex_smart(self, sitekey, url, **kwargs):
11321132
**kwargs)
11331133
return result
11341134

1135-
def altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs):
1135+
def altcha(self, pageurl, **kwargs):
11361136
'''Wrapper for solving Altcha Captcha.
11371137
11381138
Parameters
11391139
__________
11401140
pageurl : str
11411141
Full URL of the page where you solve the captcha.
1142-
challenge_url : str
1142+
challenge_url : str, optional
11431143
The value of the 'challenge_url' parameter for the 'altcha-widget' element containing the captcha on the page.
1144-
You can send either challenge_url or challenge_json parameter, but not two of it simultaneously.
1145-
challenge_json : str
1146-
The contents of the file from the 'challenge_url' parameter. You can send either challenge_url or challenge_json
1147-
parameter, but not two of it simultaneously.
1144+
At least one of the parameters 'challenge_url', 'challenge_json' must be passed.
1145+
challenge_json : str, optional
1146+
The contents of the file from the 'challenge_url' parameter.
1147+
At least one of the parameters 'challenge_url', 'challenge_json' must be passed.
11481148
proxy : dict, optional
11491149
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
11501150
11511151
'''
11521152

1153-
if (challenge_url is None) == (challenge_json is None):
1154-
raise ValidationException(
1155-
'You must provide exactly one of challenge_url or challenge_json'
1156-
)
1157-
params = {
1158-
'pageurl': pageurl,
1159-
'method': "altcha",
1160-
**kwargs,
1161-
}
1162-
if challenge_url is not None:
1163-
params['challenge_url'] = challenge_url
1164-
if challenge_json is not None:
1165-
params['challenge_json'] = challenge_json
1153+
result = self.solve(
1154+
pageurl=pageurl,
1155+
method="altcha",
1156+
**kwargs)
11661157

1167-
return self.solve(**params)
1158+
return result
11681159

11691160

11701161
def solve(self, timeout=0, polling_interval=0, **kwargs):

0 commit comments

Comments
 (0)