Skip to content
Open
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
7 changes: 5 additions & 2 deletions zabbix_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def send_api_request(self, method: str, params: Optional[dict] = None,
headers=headers,
method='POST'
)
req.timeout = self.timeout


# Disable SSL certificate validation if needed.
if not self.validate_certs:
Expand All @@ -360,7 +360,10 @@ def send_api_request(self, method: str, params: Optional[dict] = None,
ctx = None

try:
resp = ul.urlopen(req, context=ctx)
if self.timeout:
Copy link

Choose a reason for hiding this comment

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

Why do we want to check if the timeout is set before passing it?
urlopen uses the socket's global default which, according to the docs, is None by default.

So IMO, we don't need to be defensive here and just pass the timeout, no matter what.

NOTE: I am not affiliated with zabbix_utils, merely a user of the project.

resp = ul.urlopen(req, context=ctx, timeout=self.timeout)
else:
resp = ul.urlopen(req, context=ctx)
resp_json = json.loads(resp.read().decode('utf-8'))
except URLError as err:
raise ProcessingError(f"Unable to connect to {self.url}:", err) from None
Expand Down