Coder Social home page Coder Social logo

Python3 compatibility about py-zabbix HOT 12 CLOSED

adubkov avatar adubkov commented on August 16, 2024
Python3 compatibility

from py-zabbix.

Comments (12)

adubkov avatar adubkov commented on August 16, 2024

If use decode method to convert bytes to string it might help:

        data_len = struct.pack('<Q', len(request))
        packet = 'ZBXD\x01' + data_len.decode() + request

Need to verify on 2 and 3 version of python

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

PR updated: #15

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

Decode was not applied yet. But I will test it soon

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

@blacked your advice works on python 2 and 3 but I got this new error:

File "/usr/local/lib/python3.4/dist-packages/zabbix/sender.py", line 225, in send
packet = self.__create_packet(request)
File "/usr/local/lib/python3.4/dist-packages/zabbix/sender.py", line 175, in __create_packet
':'.join(x.encode('hex') for x in packet))
File "/usr/local/lib/python3.4/dist-packages/zabbix/sender.py", line 175, in
':'.join(x.encode('hex') for x in packet))
LookupError: 'hex' is not a text encoding; use codecs.encode() to handle arbitrary codecs

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

What is objective of this code?

logger.debug('%s.__create_packet (hex): %s', self.cn,
                     ':'.join(x.encode('hex') for x in packet))

from py-zabbix.

adubkov avatar adubkov commented on August 16, 2024

This is just output debug info about packet in HEX.
I think binascii will help add python2\3 compatibility:

import binascii
logger.debug('%s.__create_packet (hex): %s', self.cn,
                     ':'.join(binascii.hexlify(x.encode()) for x in packet))

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

Python3 don't works :(

TypeError: sequence item 0: expected str instance, bytes found

I tried put:

':'.join(binascii.hexlify(x) for x in packet))

But I got this error:

TypeError: 'str' does not support the buffer interface

I am confuse :(

from py-zabbix.

gomex avatar gomex commented on August 16, 2024

I fixed! :)

Please take a look: #15

from py-zabbix.

adubkov avatar adubkov commented on August 16, 2024

@gomex i updated version in pip, now it's 0.6.0:

pip install --upgrade py-zabbix

from py-zabbix.

danielbenzvi avatar danielbenzvi commented on August 16, 2024

This actually broke the functionality on Python 2.7.10 (Mac OS X).

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/zabbix/sender.py", line 177, in __create_packet
packet = 'ZBXD\x01' + data_len.decode() + request
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 0: ordinal not in range(128)

I haven't tested other architectures.

from py-zabbix.

adubkov avatar adubkov commented on August 16, 2024

@danielbenzvi can you try with?

packet = 'ZBXD\x01' + data_len.decode('utf-8') + request

Actually I tested on 2.7.9, and it works. Also what metric you try to send?

from py-zabbix.

adubkov avatar adubkov commented on August 16, 2024

fixed #17

from py-zabbix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.