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

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

      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.

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

              Created:
              Updated:
              Resolved: