Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-21195

python code example for ZBX protocol is not compatible with Pyton3

    XMLWordPrintable

Details

    • Documentation task
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • None
    • 6.4 (plan)
    • Documentation (D)
    • None
    • Team A
    • Sprint 90 (Jul 2022), Sprint 91 (Aug 2022)
    • 0.25

    Description

      The code on this page is not compatible with Python 3. 

      https://www.zabbix.com/documentation/current/en/manual/appendix/protocols/header_datalen

      packet = "ZBXD\1" + struct.pack('<Q', len(data)) + data
      

      it fails with error:

      TypeError: can only concatenate str (not "bytes") to str
      

       
      Here is modified code line which works for v3:

      packet = "ZBXD\1" + struct.pack('<Q', len(data)).decode() + data
      

      i.e. we need to convert a middle part to string by calling method .decode() to it.

      I verified result and it's correct. And it works with Python v2 too.

      Attachments

        Activity

          People

            martins-v Martins Valkovskis
            zalex_ua Oleksii Zagorskyi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: