If we got bogus XML that can't be parsed, provide a better error message instead of a trace. Fixes #77

This commit is contained in:
Matt Martz 2014-06-25 11:06:42 -05:00
parent c0cd0d1666
commit 3558b22de1
1 changed files with 26 additions and 18 deletions

View File

@ -314,6 +314,7 @@ def getConfig():
if int(uh.code) != 200:
return None
uh.close()
try:
try:
root = ET.fromstring(''.encode().join(configxml))
config = {
@ -328,6 +329,9 @@ def getConfig():
'times': getAttributesByTagName(root, 'times'),
'download': getAttributesByTagName(root, 'download'),
'upload': getAttributesByTagName(root, 'upload')}
except SyntaxError:
print_('Failed to parse speedtest.net configuration')
sys.exit(1)
del root
del configxml
return config
@ -347,12 +351,16 @@ def closestServers(client, all=False):
if int(uh.code) != 200:
return None
uh.close()
try:
try:
root = ET.fromstring(''.encode().join(serversxml))
elements = root.getiterator('server')
except AttributeError:
root = DOM.parseString(''.join(serversxml))
elements = root.getElementsByTagName('server')
except SyntaxError:
print_('Failed to parse list of speedtest.net servers')
sys.exit(1)
servers = {}
for server in elements:
try: