简体   繁体   中英

pynag with python3.6 TypeError

I'm trying to read my nagios config data as follows:

pynag.Model.cfg_file = "path_to_nagios.cfg"
all_hosts = pynag.Model.Host.objects.all"

This returns an error TypeError: endswith first arg must be bytes or a tuple of bytes

From what I've read so far, it seems that it's related to how files are opened in python3 Do you know how to correct this? Thanks.

The fix was in the library code. The def parse_file() is opening files as 'rb'. The reason this is an error in Python 3 and not Python 2 is that Python 2 treats bytes as an alias or synonym for str. It doesn't make a distinction between byte strings and unicode strings as is done in Python 3.

In pynag/Parsers/ init .py changed

lines = open(self.filename, 'rb').readlines()

to

lines = open(self.filename, 'r').readlines()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM