Skip to content

Commit

Permalink
reduce time to wait and remove after function for getting new auth af…
Browse files Browse the repository at this point in the history
…ter 403
  • Loading branch information
datawhores committed Jul 23, 2024
1 parent a75eaa5 commit d6a40bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
21 changes: 1 addition & 20 deletions ofscraper/classes/sessionmanager/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CustomTenacity(AsyncRetrying):
"""

def __init__(self, wait_random=None, wait_exponential=None, *args, **kwargs):
super().__init__(*args, after=self._after_func, **kwargs)
super().__init__(*args, **kwargs)
self.wait_random = wait_random or tenacity.wait.wait_random(
min=constants.getattr("OF_MIN_WAIT_SESSION_DEFAULT"),
max=constants.getattr("OF_MAX_WAIT_SESSION_DEFAULT"),
Expand All @@ -157,25 +157,6 @@ def _wait_picker(self, retry_state) -> None:
logging.getLogger("shared").debug(f"sleeping for {sleep} seconds before retry")
return sleep

def _after_func(self, retry_state) -> None:
exception = retry_state.outcome.exception()
if isinstance(
exception, (aiohttp.ClientResponseError, aiohttp.ClientError)
) and (
(
getattr(exception, "status_code", None)
or getattr(exception, "status", None) in {403}
)
):
auth_requests.read_request_auth()
elif isinstance(exception, httpx.HTTPStatusError) and (
(
getattr(exception.response, "status_code", None)
or getattr(exception.response, "status", None)
)
in {403}
):
auth_requests.read_request_auth()


class sessionManager:
Expand Down
4 changes: 2 additions & 2 deletions ofscraper/const/values/req/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
SESSION_MANAGER_SYNC_SEM_DEFAULT = 3
SESSION_MANAGER_SEM_DEFAULT = 10

OF_MIN_WAIT_SESSION_DEFAULT = 4
OF_MAX_WAIT_SESSION_DEFAULT = 20
OF_MIN_WAIT_SESSION_DEFAULT = 2
OF_MAX_WAIT_SESSION_DEFAULT = 6
OF_MIN_WAIT_EXPONENTIAL_SESSION_DEFAULT = 16
OF_MAX_WAIT_EXPONENTIAL_SESSION_DEFAULT = 128
OF_NUM_RETRIES_SESSION_DEFAULT = 10
Expand Down

0 comments on commit d6a40bd

Please sign in to comment.