Skip to content

Commit

Permalink
Added wait_timeout parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Xewdy444 committed Nov 28, 2023
1 parent e2aeb57 commit 5867867
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions playwright_recaptcha/recaptchav2/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ async def solve_recaptcha(
*,
attempts: Optional[int] = None,
wait: bool = False,
wait_timeout: float = 30,
image_challenge: bool = False,
) -> str:
"""
Expand All @@ -586,8 +587,9 @@ async def solve_recaptcha(
The number of solve attempts, by default 5.
wait : bool, optional
Whether to wait for the reCAPTCHA to appear, by default False.
RecaptchaNotFoundError will be raised if the reCAPTCHA has not appeared
after 30 seconds.
wait_timeout : float, optional
The amount of time in seconds to wait for the reCAPTCHA to appear,
by default 30. Only used if `wait` is True.
image_challenge : bool, optional
Whether to solve the image challenge, by default False.
Expand All @@ -607,7 +609,7 @@ async def solve_recaptcha(
RecaptchaSolveError
If the reCAPTCHA could not be solved.
"""
if self._capsolver_api_key is None and image_challenge:
if image_challenge and self._capsolver_api_key is None:
raise CapSolverError(
"You must provide a CapSolver API key to solve image challenges."
)
Expand All @@ -618,7 +620,7 @@ async def solve_recaptcha(
if wait:
retry = AsyncRetrying(
sleep=self._page.wait_for_timeout,
stop=stop_after_delay(30),
stop=stop_after_delay(wait_timeout),
wait=wait_fixed(0.25),
retry=retry_if_exception_type(RecaptchaNotFoundError),
reraise=True,
Expand Down
10 changes: 6 additions & 4 deletions playwright_recaptcha/recaptchav2/sync_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def solve_recaptcha(
*,
attempts: Optional[int] = None,
wait: bool = False,
wait_timeout: float = 30,
image_challenge: bool = False,
) -> str:
"""
Expand All @@ -529,8 +530,9 @@ def solve_recaptcha(
The number of solve attempts, by default 5.
wait : bool, optional
Whether to wait for the reCAPTCHA to appear, by default False.
RecaptchaNotFoundError will be raised if the reCAPTCHA has not appeared
after 30 seconds.
wait_timeout : float, optional
The amount of time in seconds to wait for the reCAPTCHA to appear,
by default 30. Only used if `wait` is True.
image_challenge : bool, optional
Whether to solve the image challenge, by default False.
Expand All @@ -550,7 +552,7 @@ def solve_recaptcha(
RecaptchaSolveError
If the reCAPTCHA could not be solved.
"""
if self._capsolver_api_key is None and image_challenge:
if image_challenge and self._capsolver_api_key is None:
raise CapSolverError(
"You must provide a CapSolver API key to solve image challenges."
)
Expand All @@ -561,7 +563,7 @@ def solve_recaptcha(
if wait:
retry = Retrying(
sleep=self._page.wait_for_timeout,
stop=stop_after_delay(30),
stop=stop_after_delay(wait_timeout),
wait=wait_fixed(0.25),
retry=retry_if_exception_type(RecaptchaNotFoundError),
reraise=True,
Expand Down

0 comments on commit 5867867

Please sign in to comment.