Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions sickbeard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def getURLFileLike(url, validate=False, cookies = cookielib.CookieJar(), passwor
# Before python 2.7.9, there was no built-in way to validate SSL certificates
# Since our default is not to validate, it is of low priority to make it available here
if validate and sys.version_info < (2, 7, 9):
logger.log(u"The SSL certificate will not be validated for " + url + "(python 2.7.9+ required)", logger.MESSAGE)
logger.log(u"The SSL certificate will not be validated for " + req_to_str(url) + "(python 2.7.9+ required)", logger.MESSAGE)

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),
MultipartPostHandler.MultipartPostHandler,
Expand All @@ -224,42 +224,42 @@ def getURLFileLike(url, validate=False, cookies = cookielib.CookieJar(), passwor
return opener.open(url)

except urllib2.HTTPError, e:
logger.log(u"HTTP error " + str(e.code) + " while loading URL " + url, logger.WARNING)
logger.log(u"HTTP error " + str(e.code) + " while loading URL " + req_to_str(url), logger.WARNING)
if throw_exc:
raise
else:
return None

except urllib2.URLError, e:
logger.log(u"URL error " + str(e.reason) + " while loading URL " + url, logger.WARNING)
logger.log(u"URL error " + str(e.reason) + " while loading URL " + req_to_str(url), logger.WARNING)
if throw_exc:
raise
else:
return None

except BadStatusLine:
logger.log(u"BadStatusLine error while loading URL " + url, logger.WARNING)
logger.log(u"BadStatusLine error while loading URL " + req_to_str(url), logger.WARNING)
if throw_exc:
raise
else:
return None

except socket.timeout:
logger.log(u"Timed out while loading URL " + url, logger.WARNING)
logger.log(u"Timed out while loading URL " + req_to_str(url),, logger.WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried this pr, got syntax error here. (Double commas)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thx for letting me know.

if throw_exc:
raise
else:
return None

except ValueError:
logger.log(u"Unknown error while loading URL " + url, logger.WARNING)
logger.log(u"Unknown error while loading URL " + req_to_str(url), logger.WARNING)
if throw_exc:
raise
else:
return None

except Exception:
logger.log(u"Unknown exception while loading URL " + url + ": " + traceback.format_exc(), logger.WARNING)
logger.log(u"Unknown exception while loading URL " + req_to_str(url) + ": " + traceback.format_exc(), logger.WARNING)
if throw_exc:
raise
else:
Expand Down Expand Up @@ -830,3 +830,5 @@ def backupVersionedFile(old_file, version):
return False

return True
def req_to_str(req):
return req.get_full_url() if isinstance(req, urllib2.Request) else str(req)
7 changes: 3 additions & 4 deletions sickbeard/notifiers/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def update_library(self, ep_obj=None, host=None, username=None, password=None):
req.add_header("X-Plex-Version", "1.0")

try:
response = sickbeard.helpers.getURL(req, throw_exc=True)
response = sickbeard.helpers.getURL(req, password_mgr=pw_mgr, throw_exc=True)
auth_tree = etree.fromstring(response)
token = auth_tree.findall(".//authentication-token")[0].text
token_arg = "?X-Plex-Token=" + token
Expand All @@ -191,8 +191,7 @@ def update_library(self, ep_obj=None, host=None, username=None, password=None):

url = "http://%s/library/sections%s" % (sickbeard.PLEX_SERVER_HOST, token_arg)
try:
xml_tree = etree.fromstring(sickbeard.helpers.getURL(url))
media_container = xml_tree.getroot()
media_container = etree.fromstring(sickbeard.helpers.getURL(url))
except IOError, e:
logger.log(u"PLEX: Error while trying to contact Plex Media Server: " + ex(e), logger.ERROR)
return False
Expand All @@ -206,7 +205,7 @@ def update_library(self, ep_obj=None, host=None, username=None, password=None):
if section.attrib['type'] == "show":
url = "http://%s/library/sections/%s/refresh%s" % (sickbeard.PLEX_SERVER_HOST, section.attrib['key'], token_arg)
if sickbeard.helpers.getURLFileLike(url) is None:
logger.log(u"PLEX: Error updating library section for Plex Media Server", logger.ERROR)
logger.log(u"PLEX: Error updating library section for Plex Media Server", logger.ERROR)
return False
return True

Expand Down