Skip to content

Commit

Permalink
Bugfixes (#17)
Browse files Browse the repository at this point in the history
* Remove the 'Content-type' header
* Add as_dict() method to BaseCaptchaSolution
* Fix Content-type issues
* Minor fixes
* List all 2captcha/rucaptcha captchas supported
* Anticaptcha: fixed error that occurs when the cost parameter is missing from the service response
  • Loading branch information
sergey-scat authored Mar 13, 2023
1 parent d1c4f9b commit 410c04b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
Empty file added poc_nojs_solver.py
Empty file.
6 changes: 3 additions & 3 deletions tests/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@
CaptchaSolvingService.TWOCAPTCHA: dict(
method='POST',
url='https://2captcha.com/in.php',
headers={'Accept': 'application/json', 'Content-Type': 'application/json'},
headers={'Accept': 'application/json'},
data=dict(key=API_KEY, json=1, soft_id=2738)
),
CaptchaSolvingService.RUCAPTCHA: dict(
method='POST',
url='https://rucaptcha.com/in.php',
headers={'Accept': 'application/json', 'Content-Type': 'application/json'},
headers={'Accept': 'application/json'},
data=dict(key=API_KEY, json=1, soft_id=2738)
),
CaptchaSolvingService.ANTI_CAPTCHA: dict(
method='POST',
json=dict(clientKey=API_KEY, softId=940),
headers={'Accept': 'application/json', 'Content-Type': 'application/json'},
headers={'Accept': 'application/json'},
url='https://api.anti-captcha.com/createTask'
),
CaptchaSolvingService.AZCAPTCHA: dict(
Expand Down
10 changes: 8 additions & 2 deletions tests/test_service_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
'anti_captcha': (CaptchaType.IMAGE, CaptchaType.RECAPTCHAV2, CaptchaType.RECAPTCHAV3,
CaptchaType.FUNCAPTCHA, CaptchaType.GEETEST, CaptchaType.GEETESTV4,
CaptchaType.HCAPTCHA),
'twocaptcha': CaptchaType,
'rucaptcha': CaptchaType,
'twocaptcha': (CaptchaType.IMAGE, CaptchaType.TEXT, CaptchaType.RECAPTCHAV2,
CaptchaType.RECAPTCHAV3, CaptchaType.FUNCAPTCHA, CaptchaType.KEYCAPTCHA,
CaptchaType.GEETEST, CaptchaType.GEETESTV4, CaptchaType.HCAPTCHA,
CaptchaType.CAPY, CaptchaType.TIKTOK),
'rucaptcha': (CaptchaType.IMAGE, CaptchaType.TEXT, CaptchaType.RECAPTCHAV2,
CaptchaType.RECAPTCHAV3, CaptchaType.FUNCAPTCHA, CaptchaType.KEYCAPTCHA,
CaptchaType.GEETEST, CaptchaType.GEETESTV4, CaptchaType.HCAPTCHA,
CaptchaType.CAPY, CaptchaType.TIKTOK),
'azcaptcha': (CaptchaType.IMAGE, CaptchaType.RECAPTCHAV2, CaptchaType.RECAPTCHAV3,
CaptchaType.HCAPTCHA, CaptchaType.FUNCAPTCHA),
'cptch_net': (CaptchaType.IMAGE, CaptchaType.RECAPTCHAV2, CaptchaType.RECAPTCHAV3),
Expand Down
6 changes: 5 additions & 1 deletion unicaps/_captcha/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import enum
import importlib
from abc import ABC
from dataclasses import dataclass, fields, MISSING
from dataclasses import asdict, dataclass, fields, MISSING
from typing import Dict


Expand Down Expand Up @@ -91,3 +91,7 @@ def get_captcha_class(cls) -> BaseCaptcha:

def __str__(self):
return '\n'.join(str(getattr(self, field.name)) for field in fields(self))

def as_dict(self):
""" Get solution data as Python dictionary """
return asdict(self)
7 changes: 6 additions & 1 deletion unicaps/_service/anti_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,14 @@ def parse_response(self, response) -> dict:

solution = solution_class(*args, **kwargs)

if "cost" in response_data:
cost = response_data.pop("cost")
else:
cost = None

return dict(
solution=solution,
cost=response_data.pop("cost"),
cost=cost,
extra=response_data
)

Expand Down
4 changes: 1 addition & 3 deletions unicaps/_service/captcha_guru.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ def _decorator(cls):
class Wrapper:
""" A wrapper for *TaskRequest class """
def __init__(self, *args, **kwargs):
# print(f"__init__() called with args: {args} and kwargs: {kwargs}")
self.decorated_obj = cls(*args, **kwargs)

def prepare(self, *args, **kwargs):
result = self.decorated_obj.prepare(*args, **kwargs)
if 'data' in result:
result['params'] = result['data']
del result['data']
result['params'] = result.pop('data')
result['method'] = 'GET'

if 'soft_id' in result['params']:
Expand Down
4 changes: 1 addition & 3 deletions unicaps/_service/deathbycaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def prepare(self, **kwargs) -> dict:
""" Prepare the request """

request = super().prepare(**kwargs)
request['headers'].pop('Content-Type')

method = kwargs.get('method', 'GET')
data_or_params = 'data' if method == 'POST' else 'params'
Expand All @@ -58,8 +57,7 @@ def prepare(self, **kwargs) -> dict:
'url': self._service.BASE_URL + kwargs.get('url', ''),
data_or_params: dict(
authtoken=self._service.api_key
),
# 'follow_redirects': True
)
})
return request

Expand Down
3 changes: 1 addition & 2 deletions unicaps/_transport/http_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def prepare(self, **kwargs) -> Dict:

request = super().prepare(**kwargs)
request.update(
dict(headers={'Accept': 'application/json',
'Content-Type': 'application/json'})
dict(headers={'Accept': 'application/json'})
)
return request

Expand Down

0 comments on commit 410c04b

Please sign in to comment.