コード例 #1
0
    def test_fail_aiorecaptcha_v3_proxyless_context(self):
        with ReCaptchaV3TaskProxyless.aioReCaptchaV3TaskProxyless(
                anticaptcha_key=self.anticaptcha_key_fail) as recaptcha:
            # check response type
            assert (type(recaptcha) is
                    ReCaptchaV3TaskProxyless.aioReCaptchaV3TaskProxyless)

            response = yield recaptcha.captcha_handler(
                websiteURL="https://www.google.com/recaptcha/api2/demo",
                websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
                minScore=0.3,
                pageAction="login_test",
            )
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "errorCode",
                "errorDescription"] == list(response.keys())
        # check error code
        assert response["errorId"] == 1

        with ReCaptchaV3TaskProxyless.aioReCaptchaV3TaskProxyless(
                anticaptcha_key=self.anticaptcha_key_fail) as recaptcha:
            with pytest.raises(ValueError):
                assert recaptcha.captcha_handler(
                    websiteURL="https://www.google.com/recaptcha/api2/demo",
                    websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
                    minScore=0.1,
                    pageAction="login_test",
                )
コード例 #2
0
 def test_fail_recaptcha3_value_context(self):
     with ReCaptchaV3TaskProxyless.ReCaptchaV3TaskProxyless(
             anticaptcha_key=self.anticaptcha_key_fail) as recaptcha:
         with pytest.raises(ValueError):
             assert recaptcha.captcha_handler(
                 websiteURL="https://www.google.com/recaptcha/api2/demo",
                 websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
                 minScore=0.1,
                 pageAction="login_test",
             )
コード例 #3
0
    async def test_response_aiorecaptcha3(self):
        recaptcha = ReCaptchaV3TaskProxyless.aioReCaptchaV3TaskProxyless(
            anticaptcha_key=self.anticaptcha_key_fail)
        # check response type
        assert isinstance(recaptcha,
                          ReCaptchaV3TaskProxyless.aioReCaptchaV3TaskProxyless)

        response = await recaptcha.captcha_handler(
            websiteURL="https://www.google.com/recaptcha/api2/demo",
            websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
            minScore=ReCaptchaV3TaskProxyless.MIN_SCORES[0],
            pageAction="login_test",
        )
        # check response type
        assert isinstance(response, dict)
        # check all dict keys
        assert ["errorId", "errorCode",
                "errorDescription"] == list(response.keys())
コード例 #4
0
    def test_true_recaptcha_v3_proxyless(self):
        recaptcha = ReCaptchaV3TaskProxyless.ReCaptchaV3TaskProxyless(
            anticaptcha_key=self.anticaptcha_key_true)
        # check response type
        assert type(
            recaptcha) is ReCaptchaV3TaskProxyless.ReCaptchaV3TaskProxyless

        response = recaptcha.captcha_handler(
            websiteURL="https://www.google.com/recaptcha/api2/demo",
            websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
            minScore=0.3,
            pageAction="login_test",
        )
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "errorCode", "errorDescription",
                "taskId"] == list(response.keys())
        # check error code
        # TODO change to `0`
        assert response["errorId"] == 31
コード例 #5
0
from python3_anticaptcha import ReCaptchaV3TaskProxyless

ANTICAPTCHA_KEY = "ae23fffcfaa29b170e3843e3a486ef19"

"""
WARNING:

`minScore` param can be only in [0.3, 0.5, 0.7]
"""

# Пример показывает работу антикапчи с ReCaptcha v3.
# Это метод для работы без прокси
result = ReCaptchaV3TaskProxyless.ReCaptchaV3TaskProxyless(anticaptcha_key=ANTICAPTCHA_KEY).captcha_handler(
    websiteURL="https://some_page_link",
    websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    minScore=0.3,
    pageAction="login",
)
print(result)

# contextmanager
with ReCaptchaV3TaskProxyless.ReCaptchaV3TaskProxyless(anticaptcha_key=ANTICAPTCHA_KEY) as recaptcha:
    response = recaptcha.captcha_handler(
        websiteURL="https://some_page_link",
        websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
        minScore=0.3,
        pageAction="login",
    )
print(response)

# Асинхронный пример