Skip to content

Commit dc3537f

Browse files
Server choosing was been added. Check callback was been added. #RC-252
1 parent c9ef5a4 commit dc3537f

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

twocaptcha/api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class ApiException(Exception):
1212

1313

1414
class ApiClient():
15+
def __init__(self, post_url = '2captcha.com'):
16+
self.post_url = post_url
17+
18+
1519
def in_(self, files={}, **kwargs):
1620
'''
1721
@@ -39,10 +43,11 @@ def in_(self, files={}, **kwargs):
3943
'''
4044

4145
try:
46+
current_url = 'https://'+self.post_url+'/in.php'
4247
if files:
4348

4449
files = {key: open(path, 'rb') for key, path in files.items()}
45-
resp = requests.post('https://2captcha.com/in.php',
50+
resp = requests.post(current_url,
4651
data=kwargs,
4752
files=files)
4853

@@ -51,12 +56,12 @@ def in_(self, files={}, **kwargs):
5156
elif 'file' in kwargs:
5257

5358
with open(kwargs.pop('file'), 'rb') as f:
54-
resp = requests.post('https://2captcha.com/in.php',
59+
resp = requests.post(current_url,
5560
data=kwargs,
5661
files={'file': f})
5762

5863
else:
59-
resp = requests.post('https://2captcha.com/in.php',
64+
resp = requests.post(current_url,
6065
data=kwargs)
6166

6267
except requests.RequestException as e:
@@ -96,7 +101,8 @@ def res(self, **kwargs):
96101
'''
97102

98103
try:
99-
resp = requests.get('https://2captcha.com/res.php', params=kwargs)
104+
current_url_out = 'https://'+self.post_url+'/res.php'
105+
resp = requests.get(current_url_out, params=kwargs)
100106

101107
if resp.status_code != 200:
102108
raise NetworkException(f'bad response: {resp.status_code}')

twocaptcha/solver.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ def __init__(self,
3737
callback=None,
3838
defaultTimeout=120,
3939
recaptchaTimeout=600,
40-
pollingInterval=10):
40+
pollingInterval=10,
41+
server = '2captcha.com'):
4142

4243
self.API_KEY = apiKey
4344
self.soft_id = softId
4445
self.callback = callback
4546
self.default_timeout = defaultTimeout
4647
self.recaptcha_timeout = recaptchaTimeout
4748
self.polling_interval = pollingInterval
48-
49-
self.api_client = ApiClient()
49+
self.api_client = ApiClient(post_url = str(server))
5050
self.max_files = 9
5151
self.exceptions = SolverExceptions
5252

@@ -396,14 +396,13 @@ def solve(self, timeout=0, polling_interval=0, **kwargs):
396396
id_ = self.send(**kwargs)
397397
result = {'captchaId': id_}
398398

399-
if self.has_callback:
400-
return result
399+
if self.callback is None:
401400

402-
timeout = float(timeout or self.default_timeout)
403-
sleep = int(polling_interval or self.polling_interval)
401+
timeout = float(timeout or self.default_timeout)
402+
sleep = int(polling_interval or self.polling_interval)
404403

405-
code = self.wait_result(id_, timeout, sleep)
406-
result.update({'code': code})
404+
code = self.wait_result(id_, timeout, sleep)
405+
result.update({'code': code})
407406

408407
return result
409408

0 commit comments

Comments
 (0)