Skip to content
New issue

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

Add global http timeout to the session #61

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tyora/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .utils import find_link, parse_form

HTTP_TIMEOUT = int(os.getenv("HTTP_TIMEOUT", 10))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for the conversion of HTTP_TIMEOUT from environment variable to integer to prevent runtime errors if the environment variable is not a valid integer.

- HTTP_TIMEOUT = int(os.getenv("HTTP_TIMEOUT", 10))
+ try:
+     HTTP_TIMEOUT = int(os.getenv("HTTP_TIMEOUT", 10))
+ except ValueError:
+     logger.error("Invalid HTTP_TIMEOUT value. Using default of 10 seconds.")
+     HTTP_TIMEOUT = 10

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
HTTP_TIMEOUT = int(os.getenv("HTTP_TIMEOUT", 10))
try:
HTTP_TIMEOUT = int(os.getenv("HTTP_TIMEOUT", 10))
except ValueError:
logger.error("Invalid HTTP_TIMEOUT value. Using default of 10 seconds.")
HTTP_TIMEOUT = 10

logger = logging.getLogger(__name__)

try:
Expand All @@ -33,6 +34,10 @@ def __init__(
{"User-Agent": user_agent(os.path.basename(sys.argv[0]), __version__)}
)

def request(self, *args, **kwargs):
kwargs.setdefault("timeout", HTTP_TIMEOUT)
return super(MoocfiCsesSession, self).request(*args, **kwargs)

@property
def is_logged_in(self) -> bool:
res = self.get(urljoin(self.base_url, "list"))
Expand Down
Loading