Zabbix-utils library ignores API timeout parameter

XMLWordPrintable

    • Type: Problem report
    • Resolution: Fixed
    • Priority: Major
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • 5

      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):

      **

       

      Ticket registered from : 

      https://github.com/zabbix/python-zabbix-utils/issues/34

      Customer reported to us : 

      https://support.zabbix.com/browse/ER-18797

       

            Assignee:
            Aleksandr Iantsen
            Reporter:
            Petro Sklyar
            Team C
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - Not Specified
                Not Specified
                Logged:
                Time Spent - 18h
                18h