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

    • Incident report
    • Status: Confirmed
    • Trivial
    • Resolution: Unresolved
    • None
    • None
    • Documentation (D)
    • None

    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

            zabbix.dev Zabbix Development Team
            zalex_ua Oleksii Zagorskyi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: