ws: log expat errors, and return failure

This commit is contained in:
Benjamin Dauvergne 2012-12-07 15:50:42 +01:00
parent f4a6e5e4ea
commit 6672fee61c
1 changed files with 11 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import requests
from requests.exceptions import ConnectionError
import os.path
import xml.etree.ElementTree as etree
from xml.parsers.expat import ExpatError
import collections
import logging
@ -40,7 +41,11 @@ class BlackboardConnector(object):
def _get_course_helper(self, r):
r.encoding = 'utf-8'
if r.status_code == 200 and r.content.startswith('<'):
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
try:
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
except ExpatError:
logger.exception('ExpatError %s', r.content)
return False, 'Erreur BlackBoard'
info_message_elt = x.find('infoMessage')
course_elts = x.findall('*/course')
courses = []
@ -133,7 +138,11 @@ class BlackboardConnector(object):
except ConnectionError:
return True, GetCategoryResponse('', [])
if r.status_code == 200 and r.content.startswith('<'):
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
try:
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
except ExpatError:
logger.exception('ExpatError %s', r.content)
return False, 'Erreur BlackBoard'
info_message_elt = x.find('infoMessage')
category_elts = x.findall('categories/category')
categories = []