Use status_code to stop requesting url

This commit is contained in:
Ruud
2014-09-17 12:59:24 +02:00
parent 0358378cae
commit 4a9452672a
2 changed files with 12 additions and 4 deletions
@@ -187,11 +187,12 @@ class Base(NZBProvider, RSS):
self.limits_reached[host] = False
return data
except HTTPError as e:
if e.response.status_code == 503:
sc = e.response.status_code
if sc in [503, 429]:
response = e.read().lower()
if 'maximum api' in response or 'download limit' in response:
if sc == 429 or 'maximum api' in response or 'download limit' in response:
if not self.limits_reached.get(host):
log.error('Limit reached for newznab provider: %s', host)
log.error('Limit reached / to many requests for newznab provider: %s', host)
self.limits_reached[host] = time.time()
return 'try_next'
+8 -1
View File
@@ -198,6 +198,7 @@ class Plugin(object):
del self.http_failed_disabled[host]
self.wait(host)
status_code = None
try:
kwargs = {
@@ -212,6 +213,7 @@ class Plugin(object):
log.info('Opening url: %s %s, data: %s', (method, url, [x for x in data.keys()] if isinstance(data, dict) else 'with data'))
response = r.request(method, url, **kwargs)
status_code = response.status_code
if response.status_code == requests.codes.ok:
data = response.content
else:
@@ -224,6 +226,11 @@ class Plugin(object):
# Save failed requests by hosts
try:
# To many requests
if status_code == 429:
self.http_failed_request[host] = time.time()
if not self.http_failed_request.get(host):
self.http_failed_request[host] = 1
else:
@@ -255,7 +262,7 @@ class Plugin(object):
if wait > 0:
log.debug('Waiting for %s, %d seconds', (self.getName(), wait))
time.sleep(wait)
time.sleep(min(wait, 30))
def beforeCall(self, handler):
self.isRunning('%s.%s' % (self.getName(), handler.__name__))