[mythtv-commits] Ticket #12455: tmdb3.py crashes with status code 1
MythTV
noreply at mythtv.org
Tue Nov 3 19:16:09 UTC 2015
#12455: tmdb3.py crashes with status code 1
-----------------------------------------+--------------------------------
Reporter: spmorton@… | Owner:
Type: Patch - Bug Fix | Status: infoneeded_new
Priority: minor | Milestone: unknown
Component: MythTV - Mythmetadatalookup | Version: Unspecified
Severity: medium | Resolution:
Keywords: | Ticket locked: 0
-----------------------------------------+--------------------------------
Comment (by mharbudd@…):
I took what sargenthp did and made the improvements suggested by dekarl.
Requires changes to two files.
First in '''/usr/lib/python2.7/dist-
packages/MythTV/tmdb3/tmdb_exceptions.py'''
I add one line to the ''TMDBHTTPError'' function so that the headers are
no longer discarded on an error, changing it to be:
{{{
class TMDBHTTPError(TMDBError):
def __init__(self, err):
self.httperrno = err.code
self.response = err.fp.read()
self.headers = err.headers
super(TMDBHTTPError, self).__init__(str(err))
}}}
Then the ''readJSON'' function in '''/usr/lib/python2.7/dist-
packages/MythTV/tmdb3/request.py''' is altered to be:
{{{
def readJSON(self):
"""Parse result from specified URL as JSON data."""
url = self.get_full_url()
tries = 0
while tries < 100:
try:
# catch HTTP error from open()
data = json.load(self.open())
break
except TMDBHTTPError, e:
try:
# try to load whatever was returned
data = json.loads(e.response)
except:
# cannot parse json, just raise existing error
raise e
else:
# Check for error code of 25 which means we are doing
more than 40 requests per 10 seconds
if data.get('status_code', 1) ==25:
# Sleep and retry query.
if DEBUG:
print 'Retry after {0}
seconds'.format(max(float(e.headers['retry-after']),10))
time.sleep(max(float(e.headers['retry-
after']),10))
continue
else:
# response parsed, try to raise error from TMDB
handle_status(data, url)
# no error from TMDB, just raise existing error
raise e
handle_status(data, url)
if DEBUG:
import pprint
pprint.PrettyPrinter().pprint(data)
return data
}}}
--
Ticket URL: <https://code.mythtv.org/trac/ticket/12455#comment:5>
MythTV <http://www.mythtv.org>
MythTV Media Center
More information about the mythtv-commits
mailing list