Make middleware.py Python 2.6 compatible
Fixes bug 1206256 In Python 2.6 xml.etree.ElementTree.fromstring raises xml.parsers.expat.ExpatError instead of xml.etree.ElementTree.ParseError when faced with invalid xml. This change catches an import error and uses ExpatError instead of ParseError. Change-Id: I8ab41328c8eeacc28f4e01d730c73ff251df4a25
This commit is contained in:
parent
dbb8ca35fc
commit
c7936656c0
@ -24,6 +24,10 @@ Based on pecan.middleware.errordocument
|
||||
import json
|
||||
import webob
|
||||
from xml import etree as et
|
||||
try:
|
||||
from xml.etree.ElementTree import ParseError
|
||||
except ImportError:
|
||||
from xml.parsers.expat import ExpatError as ParseError
|
||||
|
||||
from ceilometer.openstack.common import log
|
||||
|
||||
@ -76,7 +80,7 @@ class ParsableErrorMiddleware(object):
|
||||
et.ElementTree.fromstring('<error_message>'
|
||||
+ '\n'.join(app_iter)
|
||||
+ '</error_message>'))]
|
||||
except et.ElementTree.ParseError as err:
|
||||
except ParseError as err:
|
||||
LOG.error('Error parsing HTTP response: %s' % err)
|
||||
body = ['<error_message>%s' % state['status_code']
|
||||
+ '</error_message>']
|
||||
|
Loading…
x
Reference in New Issue
Block a user