Browse Source

Merge branch 'feature/FixPlexNotifier' into develop

pull/1289/head
JackDandy 5 years ago
parent
commit
29e4524cbd
  1. 1
      CHANGES.md
  2. 4
      sickbeard/notifiers/boxcar2.py
  3. 8
      sickbeard/notifiers/nmj.py
  4. 20
      sickbeard/notifiers/nmjv2.py
  5. 14
      sickbeard/notifiers/plex.py
  6. 13
      sickbeard/notifiers/pushover.py
  7. 3
      sickbeard/notifiers/pytivo.py
  8. 16
      sickbeard/notifiers/xbmc.py

1
CHANGES.md

@ -110,6 +110,7 @@
* Add new test for wanted whole first season (add show)
* Change SickGear-NG version
* Fix "Update shows on startup" (change update_shows_on_start = 0 in config.ini, restart SG, then update)
* Fix Plex notifier, PY2 urllib2.urlopen has no `with` context manager and six.moves.urllib.request.urlopen does not provide
[develop changelog]

4
sickbeard/notifiers/boxcar2.py

@ -67,8 +67,8 @@ class Boxcar2Notifier(Notifier):
result = None
try:
req = urllib.request.Request('https://new.boxcar.io/api/notifications')
handle = urllib.request.urlopen(req, data)
handle.close()
http_response_obj = urllib.request.urlopen(req, data) # PY2 http_response_obj has no `with` context manager
http_response_obj.close()
except urllib.error.HTTPError as e:
if not hasattr(e, 'code'):

8
sickbeard/notifiers/nmj.py

@ -105,7 +105,8 @@ class NMJNotifier(BaseNotifier):
try:
req = urllib.request.Request(mount)
self._log_debug(u'Try to mount network drive via url: %s' % mount)
urllib.request.urlopen(req)
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
http_response_obj.close()
except IOError as e:
if hasattr(e, 'reason'):
self._log_warning(u'Could not contact Popcorn Hour on host %s: %s' % (host, e.reason))
@ -125,8 +126,9 @@ class NMJNotifier(BaseNotifier):
try:
req = urllib.request.Request(update_url)
self._log_debug(u'Sending scan update command via url: %s' % update_url)
handle = urllib.request.urlopen(req)
response = handle.read()
http_response_obj = urllib.request.urlopen(req)
response = http_response_obj.read()
http_response_obj.close()
except IOError as e:
if hasattr(e, 'reason'):
self._log_warning(u'Could not contact Popcorn Hour on host %s: %s' % (host, e.reason))

20
sickbeard/notifiers/nmjv2.py

@ -49,8 +49,9 @@ class NMJv2Notifier(BaseNotifier):
req = urllib.request.Request('%s%s%s' % (base_url, 'file_operation?', urlencode(
dict(arg0='list_user_storage_file', arg1='', arg2=instance, arg3=20, arg4='true', arg5='true',
arg6='true', arg7='all', arg8='name_asc', arg9='false', arg10='false'))))
handle = urllib.request.urlopen(req)
response = handle.read()
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
response = http_response_obj.read()
http_response_obj.close()
xml_data = parseString(response)
time.sleep(300.0 / 1000.0)
@ -60,8 +61,9 @@ class NMJv2Notifier(BaseNotifier):
reqdb = urllib.request.Request('%s%s%s' % (base_url, 'metadata_database?', urlencode(
dict(arg0='check_database',
arg1=xml_tag.replace('<path>', '').replace('</path>', '').replace('[=]', '')))))
handledb = urllib.request.urlopen(reqdb)
responsedb = handledb.read()
http_response_obj_db = urllib.request.urlopen(reqdb) # PY2 http_response_obj has no `with` context mgr
responsedb = http_response_obj_db.read()
http_response_obj.close()
xml_db = parseString(responsedb)
if '0' == xml_db.getElementsByTagName('returnValue')[0].toxml().replace(
@ -117,13 +119,15 @@ class NMJv2Notifier(BaseNotifier):
prereq = urllib.request.Request(url_scandir)
req = urllib.request.Request(url_updatedb)
handle1 = urllib.request.urlopen(prereq)
response1 = handle1.read()
http_response_obj1 = urllib.request.urlopen(prereq) # PY2 http_response_obj has no `with` context manager
response1 = http_response_obj1.read()
http_response_obj1.close()
time.sleep(300.0 / 1000.0)
handle2 = urllib.request.urlopen(req)
response2 = handle2.read()
http_response_obj2 = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
response2 = http_response_obj2.read()
http_response_obj2.close()
except IOError as e:
self._log_warning(u'Couldn\'t contact popcorn hour on host %s: %s' % (host, ex(e)))
return False

14
sickbeard/notifiers/plex.py

@ -68,8 +68,9 @@ class PLEXNotifier(Notifier):
else:
self._log_debug(u'Contacting via url: ' + url)
with urllib.request.urlopen(req) as response:
result = decode_str(response.read(), sickbeard.SYS_ENCODING)
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
result = decode_str(http_response_obj.read(), sickbeard.SYS_ENCODING)
http_response_obj.close()
self._log_debug(u'HTTP response: ' + result.replace('\n', ''))
return True
@ -173,10 +174,11 @@ class PLEXNotifier(Notifier):
token_arg = False
try:
with urllib.request.urlopen(req) as response:
auth_tree = XmlEtree.parse(response)
token = auth_tree.findall('.//authentication-token')[0].text
token_arg = '?X-Plex-Token=' + token
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
auth_tree = XmlEtree.parse(http_response_obj)
http_response_obj.close()
token = auth_tree.findall('.//authentication-token')[0].text
token_arg = '?X-Plex-Token=' + token
except urllib.error.URLError as e:
self._log(u'Error fetching credentials from plex.tv for user %s: %s' % (username, ex(e)))

13
sickbeard/notifiers/pushover.py

@ -45,10 +45,10 @@ class PushoverNotifier(Notifier):
result = False
try:
req = urllib.request.Request(DEVICE_URL)
handle = urllib.request.urlopen(req, data)
if handle:
result = handle.read()
handle.close()
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
if http_response_obj:
result = http_response_obj.read()
http_response_obj.close()
except (urllib.error.URLError, socket.timeout):
pass
@ -85,8 +85,9 @@ class PushoverNotifier(Notifier):
result = None
try:
req = urllib.request.Request(API_URL)
handle = urllib.request.urlopen(req, urlencode(params))
handle.close()
# PY2 http_response_obj has no `with` context manager
http_response_obj = urllib.request.urlopen(req, urlencode(params))
http_response_obj.close()
except urllib.error.HTTPError as e:
# HTTP status 404 if the provided email address isn't a Pushover user.

3
sickbeard/notifiers/pytivo.py

@ -75,7 +75,8 @@ class PyTivoNotifier(BaseNotifier):
request = urllib.request.Request(request_url)
try:
urllib.request.urlopen(request)
http_response_obj = urllib.request.urlopen(request) # PY2 http_response_obj has no `with` context manager
http_response_obj.close()
except urllib.error.HTTPError as e:
if hasattr(e, 'reason'):

16
sickbeard/notifiers/xbmc.py

@ -173,9 +173,9 @@ class XBMCNotifier(Notifier):
else:
self._log_debug(u'Contacting via url: ' + fixStupidEncodings(url))
response = urllib.request.urlopen(req)
result = decode_str(response.read(), sickbeard.SYS_ENCODING)
response.close()
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
result = decode_str(http_response_obj.read(), sickbeard.SYS_ENCODING)
http_response_obj.close()
self._log_debug(u'HTTP response: ' + result.replace('\n', ''))
return result
@ -279,7 +279,7 @@ class XBMCNotifier(Notifier):
##############################################################################
def _send_to_xbmc_json(self, command, host=None, username=None, password=None):
# type: () -> Union[bool, Dict]
# type: (...) -> Union[bool, Dict]
"""Handles communication to XBMC servers via JSONRPC
Args:
@ -314,19 +314,19 @@ class XBMCNotifier(Notifier):
self._log_debug(u'Contacting via url: ' + fixStupidEncodings(url))
try:
response = urllib.request.urlopen(req)
http_response_obj = urllib.request.urlopen(req) # PY2 http_response_obj has no `with` context manager
except urllib.error.URLError as e:
self._log_warning(u'Error while trying to retrieve API version for "%s": %s' % (host, ex(e)))
return False
# parse the json result
try:
result = json.load(response)
response.close()
result = json.load(http_response_obj)
http_response_obj.close()
self._log_debug(u'JSON response: ' + str(result))
return result # need to return response for parsing
except ValueError:
self._log_warning(u'Unable to decode JSON: ' + response)
self._log_warning(u'Unable to decode JSON: ' + http_response_obj)
return False
except IOError as e:

Loading…
Cancel
Save