diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 4b09f7e..263c2c0 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -15,7 +15,7 @@ jobs: max-parallel: 4 fail-fast: false matrix: - python-version: [3.6, 3.7, 3.9] + python-version: [3.7, 3.9] steps: - uses: actions/checkout@v1 diff --git a/README.md b/README.md index f11021e..7c3b4fb 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ pip install capmonster_python - Recaptcha v3 - Fun Captcha - HCaptcha +- GeeTest Usage examples - @@ -45,6 +46,19 @@ result = capmonster.join_task_result(task_id) print(result.get("gRecaptchaResponse")) ``` +#### GeeTest + +```python +from capmonster_python import GeeTestTask + +capmonster_python = GeeTestTask("API_KEY") +task_id = capmonster_python.create_task("website_url", "gt", "challenge") +result= capmonster_python.join_task_result(task_id) +print(result.get("challenge")) +print(result.get("seccode")) +print(result.get("validate")) +``` + For other examples and api documentation please visit [wiki](https://github.com/alperensert/capmonster_python/wiki) ### Migration from 1.3.2 to 2.x diff --git a/capmonster_python/__init__.py b/capmonster_python/__init__.py index 0fa5eb4..6cd7a4a 100644 --- a/capmonster_python/__init__.py +++ b/capmonster_python/__init__.py @@ -3,4 +3,5 @@ from .recaptcha_v3 import RecaptchaV3Task from .hcaptcha import HCaptchaTask from .image_to_text import ImageToTextTask +from .geetest import GeeTestTask from .utils import CapmonsterException diff --git a/capmonster_python/geetest.py b/capmonster_python/geetest.py new file mode 100644 index 0000000..179fafe --- /dev/null +++ b/capmonster_python/geetest.py @@ -0,0 +1,26 @@ +from .capmonster import Proxy, UserAgent + + +class GeeTestTask(UserAgent, Proxy): + def __init__(self, client_key): + super(GeeTestTask, self).__init__(client_key) + + def create_task(self, website_url: str, gt: str, challenge: str, + api_server_subdomain: str = None, get_lib: str = None): + data = { + "clientKey": self._client_key, + "task": { + "type": "GeeTestTask", + "websiteURL": website_url, + "gt": gt, + "challenge": challenge + } + } + data, is_user_agent = self._add_user_agent(data) + data, is_proxy = self._is_proxy_task(data) + if api_server_subdomain: + data["task"]["geetestApiServerSubdomain"] = api_server_subdomain + if get_lib: + data["task"]["geetestGetLib"] = get_lib + return self._make_request("createTask", data).get("taskId") + diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 9703ea7..7a31cd8 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -1,3 +1,5 @@ +import re +import requests import unittest from inspect import stack from os import environ @@ -5,7 +7,7 @@ client_key = environ.get("KEY") proxy = environ.get("PROXY").split(",") -acceptable_error_codes = ["ERROR_CAPTCHA_UNSOLVABLE", "ERROR_MAXIMUM_TIME_EXCEED"] +acceptable_error_codes = ["ERROR_CAPTCHA_UNSOLVABLE", "ERROR_MAXIMUM_TIME_EXCEED", "ERROR_NO_SLOT_AVAILABLE"] class TestImageToText(unittest.TestCase): @@ -52,8 +54,8 @@ def __init__(self, *args, **kwargs): } def test_proxyless_recaptchav2(self): - task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level" - "=high", "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd", + task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high", + "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd", cookies=self.dump_cookies) self.assertIs(type(task_id), int) solution = self.captcha.join_task_result(task_id) @@ -62,17 +64,23 @@ def test_proxyless_recaptchav2(self): del task_id, solution def test_proxy_recaptchav2(self): - self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0") - self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4]) - task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level" - "=high", "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd", - cookies=self.dump_cookies, no_cache=True) - self.assertIs(type(task_id), int) - solution = self.captcha.join_task_result(task_id) - self.assertIs(type(solution), dict) - self.assertIn("gRecaptchaResponse", solution) - self.captcha.disable_proxy() - self.captcha.reset_user_agent() + try: + self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0") + self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4]) + task_id = self.captcha.create_task( + "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high", + "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd", + cookies=self.dump_cookies, no_cache=True) + self.assertIs(type(task_id), int) + solution = self.captcha.join_task_result(task_id) + self.assertIs(type(solution), dict) + self.assertIn("gRecaptchaResponse", solution) + self.captcha.disable_proxy() + self.captcha.reset_user_agent() + except CapmonsterException as err: + if any(err.error_code in s for s in acceptable_error_codes): + print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code)) + pass class TestRecaptchaV3(unittest.TestCase): @@ -178,5 +186,51 @@ def test_invisible_hcaptcha(self): del solution, task_id +class TestGeeTest(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(TestGeeTest, self).__init__(*args, **kwargs) + self.captcha = GeeTestTask(client_key) + + def getProperties(self): + r = requests.get("https://2captcha.com/tr/demo/geetest").text + return re.search("gt: '(.+?)'", r).group(1), re.search("challenge: '(.+?)'", r).group(1) + + def test_proxy_geetest(self): + try: + self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0") + self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4]) + gt, challenge = self.getProperties() + task_id = self.captcha.create_task(website_url="https://2captcha.com/tr/demo/geetest", + gt=gt, challenge=challenge) + solution = self.captcha.join_task_result(task_id) + self.assertIs(type(solution), dict) + self.assertIn("challenge", solution) + self.assertIn("seccode", solution) + self.assertIn("validate", solution) + self.captcha.disable_proxy() + self.captcha.reset_user_agent() + del solution, task_id + except CapmonsterException as err: + if any(err.error_code in s for s in acceptable_error_codes): + print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code)) + pass + + def test_proxyless_geetest(self): + try: + gt, challenge = self.getProperties() + task_id = self.captcha.create_task(website_url="https://2captcha.com/tr/demo/geetest", + gt=gt, challenge=challenge) + solution = self.captcha.join_task_result(task_id) + self.assertIs(type(solution), dict) + self.assertIn("challenge", solution) + self.assertIn("seccode", solution) + self.assertIn("validate", solution) + del solution, task_id + except CapmonsterException as err: + if any(err.error_code in s for s in acceptable_error_codes): + print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code)) + pass + + if __name__ == "__main__": unittest.main()