Catch timeout errors when xbmc isn't available
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
|||||||
import socket
|
import socket
|
||||||
import traceback
|
import traceback
|
||||||
import urllib
|
import urllib
|
||||||
|
import requests
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -167,22 +168,18 @@ class XBMC(Notification):
|
|||||||
# manually fake expected response array
|
# manually fake expected response array
|
||||||
return [{'result': 'Error'}]
|
return [{'result': 'Error'}]
|
||||||
|
|
||||||
except URLError, e:
|
except requests.exceptions.Timeout:
|
||||||
if isinstance(e.reason, socket.timeout):
|
log.info2('Couldn\'t send request to XBMC, assuming it\'s turned off')
|
||||||
log.info('Couldn\'t send request to XBMC, assuming it\'s turned off')
|
return [{'result': 'Error'}]
|
||||||
return [{'result': 'Error'}]
|
|
||||||
else:
|
|
||||||
log.error('Failed sending non-JSON-type request to XBMC: %s', traceback.format_exc())
|
|
||||||
return [{'result': 'Error'}]
|
|
||||||
except:
|
except:
|
||||||
log.error('Failed sending non-JSON-type request to XBMC: %s', traceback.format_exc())
|
log.error('Failed sending non-JSON-type request to XBMC: %s', traceback.format_exc())
|
||||||
return [{'result': 'Error'}]
|
return [{'result': 'Error'}]
|
||||||
|
|
||||||
def request(self, host, requests):
|
def request(self, host, do_requests):
|
||||||
server = 'http://%s/jsonrpc' % host
|
server = 'http://%s/jsonrpc' % host
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for req in requests:
|
for req in do_requests:
|
||||||
method, kwargs = req
|
method, kwargs = req
|
||||||
data.append({
|
data.append({
|
||||||
'method': method,
|
'method': method,
|
||||||
@@ -206,13 +203,9 @@ class XBMC(Notification):
|
|||||||
log.debug('Returned from request %s: %s', (host, response))
|
log.debug('Returned from request %s: %s', (host, response))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
except URLError, e:
|
except requests.exceptions.Timeout:
|
||||||
if isinstance(e.reason, socket.timeout):
|
log.info2('Couldn\'t send request to XBMC, assuming it\'s turned off')
|
||||||
log.info('Couldn\'t send request to XBMC, assuming it\'s turned off')
|
return []
|
||||||
return []
|
|
||||||
else:
|
|
||||||
log.error('Failed sending request to XBMC: %s', traceback.format_exc())
|
|
||||||
return []
|
|
||||||
except:
|
except:
|
||||||
log.error('Failed sending request to XBMC: %s', traceback.format_exc())
|
log.error('Failed sending request to XBMC: %s', traceback.format_exc())
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user