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:
parent
c0cd0d1666
commit
3558b22de1
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue