mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix exception issue in junos_config (#24049)
ParseError execption is added to ElementTree in py2.7. Prior to py2.7 need catch ExpatError execption
This commit is contained in:
parent
3185ec94c5
commit
7d710882a8
1 changed files with 8 additions and 1 deletions
|
@ -185,6 +185,7 @@ backup_path:
|
|||
"""
|
||||
import re
|
||||
import json
|
||||
import sys
|
||||
|
||||
from xml.etree import ElementTree
|
||||
|
||||
|
@ -195,6 +196,12 @@ from ansible.module_utils.junos import check_args as junos_check_args
|
|||
from ansible.module_utils.netconf import send_request
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
if sys.version < (2, 7):
|
||||
from xml.parsers.expat import ExpatError
|
||||
ParseError = ExpatError
|
||||
else:
|
||||
ParseError = ElementTree.ParseError
|
||||
|
||||
USE_PERSISTENT_CONNECTION = True
|
||||
DEFAULT_COMMENT = 'configured by junos_config'
|
||||
|
||||
|
@ -217,7 +224,7 @@ def guess_format(config):
|
|||
try:
|
||||
ElementTree.fromstring(config)
|
||||
return 'xml'
|
||||
except ElementTree.ParseError:
|
||||
except ParseError:
|
||||
pass
|
||||
|
||||
if config.startswith('set') or config.startswith('delete'):
|
||||
|
|
Loading…
Reference in a new issue