If we fail to parse a response, log the uri

and the original response
This commit is contained in:
Hellowlol 2015-09-29 11:28:04 +02:00 committed by John
parent f7bc208fd1
commit b1e27d9bc2

View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of PlexPy. # This file is part of PlexPy.
# #
# PlexPy is free software: you can redistribute it and/or modify # PlexPy is free software: you can redistribute it and/or modify
@ -14,12 +17,11 @@
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>. # along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, helpers from plexpy import logger, helpers
from httplib import HTTPSConnection from httplib import HTTPSConnection
from httplib import HTTPConnection from httplib import HTTPConnection
import ssl import ssl
class HTTPHandler(object): class HTTPHandler(object):
""" """
Retrieve data from Plex Server Retrieve data from Plex Server
@ -88,19 +90,25 @@ class HTTPHandler(object):
return None return None
if request_status == 200: if request_status == 200:
if output_format == 'dict': try:
output = helpers.convert_xml_to_dict(request_content) if output_format == 'dict':
elif output_format == 'json': output = helpers.convert_xml_to_dict(request_content)
output = helpers.convert_xml_to_json(request_content) elif output_format == 'json':
elif output_format == 'xml': output = helpers.convert_xml_to_json(request_content)
output = helpers.parse_xml(request_content) elif output_format == 'xml':
else: output = helpers.parse_xml(request_content)
output = request_content else:
output = request_content
if return_type: if return_type:
return output, content_type return output, content_type
return output
except Exception as e:
logger.warn(u"Failed format response from uri %s to %s error %s" % (uri, output_format, e))
return None
return output
else: else:
logger.warn(u"Failed to access uri endpoint %s. Status code %r" % (uri, request_status)) logger.warn(u"Failed to access uri endpoint %s. Status code %r" % (uri, request_status))
return None return None