Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with Python 3.4 #22

Open
aherbjornsen opened this issue Sep 28, 2017 · 3 comments
Open

Does not work with Python 3.4 #22

aherbjornsen opened this issue Sep 28, 2017 · 3 comments

Comments

@aherbjornsen
Copy link

I'm trying to get this to work with python3 (currently 3.4) but can't seem to get it to work.

I receive this message:

$ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynsca
>>> from pynsca import NSCANotifier
>>> notif = NSCANotifier("nagios")
>>> notif.svc_result("localhost", "testservice", pynsca.OK, "OK: testing")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/pynsca.py", line 181, in svc_result
    buf += data
TypeError: Can't convert 'bytes' object to str implicitly
>>> 
@djmitche
Copy link
Owner

@kislik I know you did some work to make pynsca work with Python 3. Is this something you could fix?

@aherbjornsen
Copy link
Author

My knowledge of Python is very rudimentary, but I did some googling and found that the socket.recv call now returns a binary array and not a string.
I did try to add '.decode()' to the 'buf+=data' line, but that did only give an error about unknown format. I also tried to change the 'buf = '' ' line to 'buf = b''' which got rid of the initial problem but brought on other instead...
Also there's a few other bits that needs to be changed. 'itertools.izip' should now probably only be 'zip'. And 'isinstance(text, unicode)' should probably be replaced by 'isinstance(text, str)'.

@djmitche
Copy link
Owner

Indeed, it's not trivial to fix this to work with Python 3. There are some migration guides out there, though.

I would suggest using bytes for everything in this particular application, as I think the NSCA protocol is not encoding-aware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants