Enhanced Security Measures in Place:   To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Who rated this post

Glad you got it working!  fw.op() will return an xml.etree.ElementTree by default, so turning it into a string and then having to re-parse it is a (small) waste.  You're using a PanDevice object instead of the Firewall object, so I'd recommend changing that for clarity's sake.  Then lastly you know what the result looks like, so you can use xml.etree.ElementTree.findall() to get there directly:

 

from pandevice.firewall import Firewall
import xml.etree.ElementTree as ET

fw = Firewall('10.10.10.10', api_key='abcdefgh')
result = fw.op(cmd='show global-protect-gateway current-user')

# If you wanted to see the xml response as a string:
# print(ET.tostring(result, encoding='utf-8')

for elm in result.findall('./response/entry'):
  print(elm.attrib['name'] + ':')
  for e in elm:
    print(e.tag + ': ' + e.text)

 

Who rated this post