Fix typo in method

Pylint downloadutils
This commit is contained in:
angelblue05 2016-09-27 04:10:40 -05:00
parent 55438749bb
commit 8b0164d5a3

View file

@ -6,7 +6,6 @@ import json
import requests import requests
import logging import logging
import xbmc
import xbmcgui import xbmcgui
import clientinfo import clientinfo
@ -79,7 +78,7 @@ class DownloadUtils(object):
# Reserved for userclient only # Reserved for userclient only
for server in self.servers: for server in self.servers:
if server['ServerId'] == server_id: if server['ServerId'] == server_id:
self.servers.remove(s) self.servers.pop(server)
window('emby_server%s.json' % server_id, clear=True) window('emby_server%s.json' % server_id, clear=True)
window('emby_server%s.name' % server_id, clear=True) window('emby_server%s.name' % server_id, clear=True)
log.info("removing %s from available servers", server_id) log.info("removing %s from available servers", server_id)
@ -248,62 +247,63 @@ class DownloadUtils(object):
##### THE RESPONSE ##### ##### THE RESPONSE #####
log.debug(kwargs) log.debug(kwargs)
r = self._requests(action_type, session, **kwargs) response = self._requests(action_type, session, **kwargs)
if r.status_code == 204: if response.status_code == 204:
# No body in the response # No body in the response
log.debug("====== 204 Success ======") log.debug("====== 204 Success ======")
# Read response to release connection # Read response to release connection
r.content response.content
elif r.status_code == requests.codes.ok: elif response.status_code == requests.codes.ok:
try: try:
# UNICODE - JSON object # UNICODE - JSON object
r = r.json() response = response.json()
log.debug("====== 200 Success ======") log.debug("====== 200 Success ======")
log.debug("Response: %s" % r) log.debug("Response: %s", response)
return r return response
except Exception: except Exception:
if r.headers.get('content-type') != "text/html": if response.headers.get('content-type') != "text/html":
log.info("Unable to convert the response for: %s" % url) log.info("Unable to convert the response for: %s", url)
else: # Bad status code else: # Bad status code
log.error("=== Bad status response: %s ===" % r.status_code) log.error("=== Bad status response: %s ===", response.status_code)
r.raise_for_status() response.raise_for_status()
##### EXCEPTIONS ##### ##### EXCEPTIONS #####
except requests.exceptions.ConnectionError as e: except requests.exceptions.SSLError as error:
# Make the addon aware of status log.error("invalid SSL certificate for: %s", url)
if window('emby_online') != "false":
log.error("Server unreachable at: %s" % url)
window('emby_online', value="false")
except requests.exceptions.ConnectTimeout as error: except requests.exceptions.ConnectTimeout as error:
log.error("Server timeout at: %s", url) log.error("Server timeout at: %s", url)
except requests.exceptions.ConnectionError as error:
# Make the addon aware of status
if window('emby_online') != "false":
log.error("Server unreachable at: %s", url)
window('emby_online', value="false")
except requests.exceptions.HTTPError as error: except requests.exceptions.HTTPError as error:
if r.status_code == 401: if response.status_code == 401:
# Unauthorized # Unauthorized
status = window('emby_serverStatus') status = window('emby_serverStatus')
if 'X-Application-Error-Code' in r.headers: if 'X-Application-Error-Code' in response.headers:
# Emby server errors # Emby server errors
if r.headers['X-Application-Error-Code'] == "ParentalControl": if response.headers['X-Application-Error-Code'] == "ParentalControl":
# Parental control - access restricted # Parental control - access restricted
if status != "restricted": if status != "restricted":
xbmcgui.Dialog().notification( xbmcgui.Dialog().notification(heading=lang(29999),
heading=lang(29999),
message="Access restricted.", message="Access restricted.",
icon=xbmcgui.NOTIFICATION_ERROR, icon=xbmcgui.NOTIFICATION_ERROR,
time=5000) time=5000)
window('emby_serverStatus', value="restricted") window('emby_serverStatus', value="restricted")
raise Warning('restricted') raise Warning('restricted')
elif r.headers['X-Application-Error-Code'] == "UnauthorizedAccessException": elif response.headers['X-Application-Error-Code'] == "UnauthorizedAccessException":
# User tried to do something his emby account doesn't allow # User tried to do something his emby account doesn't allow
pass pass
@ -311,21 +311,16 @@ class DownloadUtils(object):
# Tell userclient token has been revoked. # Tell userclient token has been revoked.
window('emby_serverStatus', value="401") window('emby_serverStatus', value="401")
log.error("HTTP Error: %s", error) log.error("HTTP Error: %s", error)
xbmcgui.Dialog().notification( xbmcgui.Dialog().notification(heading="Error connecting",
heading="Error connecting",
message="Unauthorized.", message="Unauthorized.",
icon=xbmcgui.NOTIFICATION_ERROR) icon=xbmcgui.NOTIFICATION_ERROR)
raise Warning('401') raise Warning('401')
except requests.exceptions.SSLError as error:
log.error("invalid SSL certificate for: %s", url)
except requests.exceptions.RequestException as error: except requests.exceptions.RequestException as error:
log.error("unknown error connecting to: %s" % url) log.error("unknown error connecting to: %s", url)
return default_link return default_link
def _ensure_server(self, server_id=None): def _ensure_server(self, server_id=None):
if server_id is None and self.session_requests is None: if server_id is None and self.session_requests is None: