-
Notifications
You must be signed in to change notification settings - Fork 31
Description
When setting the timeout parameter when creating a ZabbixAPI object the timeout parameter is ignored and every request has the same timeout of about 20s.
Versions used:
Python: 3.11 zabbix-utils: 2.0.3
Example code:
logger.debug(f"Connecting to Zabbix server ...") api = ZabbixAPI(timeout=5) logger.info(f"Connected to Zabbix server")
With ENV set correctly according to the documentation.
Whatever value you set for the timeout parameter the timeout did not change.
I did digging into the urllib of Python 3.11 and traced the problem to the following code.
api.py - function send_api_request:
req = ul.Request(
self.url,
data=json.dumps(request_json).encode("utf-8"),
headers=headers,
method='POST'
)
req.timeout = self.timeout
followed by
try:
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
except ValueError as err:
raise ProcessingError("Unable to parse json:", err) from None
If you then dig into the urllib urlopen function the timeout is a parameter that needs to be provided to the function and is not taken from the request object provided to the function.
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False, context=None):