We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't we define a retry method in the instance method? Because I want to call login again in the instance method, I cannot use static methods.
api = gov.api.api("test","test") api.get_all_list(1,10)
import requests from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception, retry_if_result class api: def __init__(self, username, password): self.session = requests.session() self.session.headers = {"User-Agent": ""} self.username = username self.password = password self.token = "" self.headers = {"Authorization": f"Bearer {self.token}"} def is_retryable_exception(self, exception): if isinstance(exception, requests.exceptions.HTTPError): if exception.response.status_code == 401: self.login() return True def is_retryable_result(self, result): print("is_retryable_result") if result is None: return True if result.get("code", None) == 0: return False return True @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=(retry_if_exception(is_retryable_exception) | retry_if_result(is_retryable_result))) def login(self): return "" @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=(retry_if_exception(is_retryable_exception) | retry_if_result(is_retryable_result))) def get_all_list(self, index, pagesize): return None
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Can't we define a retry method in the instance method?
Because I want to call login again in the instance method, I cannot use static methods.
The text was updated successfully, but these errors were encountered: