From ead7e2349c414467ce2dc80ae44c9599cb5a3268 Mon Sep 17 00:00:00 2001 From: evilhero Date: Mon, 1 Apr 2019 11:03:17 -0400 Subject: [PATCH] FIX: (#2228) Fix for ExpatError being returned when CV is not responding --- mylar/cv.py | 18 ++++++++++++++---- mylar/mb.py | 34 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/mylar/cv.py b/mylar/cv.py index 91d9d24a..c243249d 100755 --- a/mylar/cv.py +++ b/mylar/cv.py @@ -24,6 +24,7 @@ import lib.feedparser import mylar import platform from bs4 import BeautifulSoup as Soup +from xml.parsers.expat import ExpatError import httplib import requests @@ -96,10 +97,19 @@ def pulldetails(comicid, type, issueid=None, offset=1, arclist=None, comicidlist return #logger.fdebug('cv status code : ' + str(r.status_code)) - dom = parseString(r.content) - - return dom - + try: + dom = parseString(r.content) + except ExpatError: + if u'Abnormal Traffic Detected' in r.content: + logger.error('ComicVine has banned this server\'s IP address because it exceeded the API rate limit.') + else: + logger.warn('[WARNING] ComicVine is not responding correctly at the moment. This is usually due to some problems on their end. If you re-try things again in a few moments, things might work') + return + except Exception as e: + logger.warn('[ERROR] Error returned from CV: %s' % e) + return + else: + return dom def getComic(comicid, type, issueid=None, arc=None, arcid=None, arclist=None, comicidlist=None): if type == 'issue': diff --git a/mylar/mb.py b/mylar/mb.py index e74eb4bc..dbbf8183 100755 --- a/mylar/mb.py +++ b/mylar/mb.py @@ -21,6 +21,7 @@ import threading import platform import urllib, urllib2 from xml.dom.minidom import parseString, Element +from xml.parsers.expat import ExpatError import requests import mylar @@ -70,8 +71,8 @@ def pullsearch(comicapi, comicquery, offset, type): try: r = requests.get(PULLURL, params=payload, verify=mylar.CONFIG.CV_VERIFY, headers=mylar.CV_HEADERS) - except Exception, e: - logger.warn('Error fetching data from ComicVine: %s' % (e)) + except Exception as e: + logger.warn('Error fetching data from ComicVine: %s' % e) return try: @@ -82,8 +83,11 @@ def pullsearch(comicapi, comicquery, offset, type): else: logger.warn('[WARNING] ComicVine is not responding correctly at the moment. This is usually due to some problems on their end. If you re-try things again in a few moments, it might work properly.') return - - return dom + except Exception as e: + logger.warn('[ERROR] Error returned from CV: %s' % e) + return + else: + return dom def findComic(name, mode, issue, limityear=None, type=None): @@ -459,24 +463,20 @@ def storyarcinfo(xmlid): try: r = requests.get(ARCPULL_URL, params=payload, verify=mylar.CONFIG.CV_VERIFY, headers=mylar.CV_HEADERS) - except Exception, e: - logger.warn('Error fetching data from ComicVine: %s' % (e)) + except Exception as e: + logger.warn('While parsing data from ComicVine, got exception: %s' % e) return -# try: -# file = urllib2.urlopen(ARCPULL_URL) -# except urllib2.HTTPError, err: -# logger.error('err : ' + str(err)) -# logger.error('There was a major problem retrieving data from ComicVine - on their end.') -# return -# arcdata = file.read() -# file.close() + try: - arcdom = parseString(r.content) #(arcdata) + arcdom = parseString(r.content) except ExpatError: if u'<title>Abnormal Traffic Detected' in r.content: - logger.error("ComicVine has banned this server's IP address because it exceeded the API rate limit.") + logger.error('ComicVine has banned this server\'s IP address because it exceeded the API rate limit.') else: - logger.warn('While parsing data from ComicVine, got exception: %s for data: %s' % (str(e), r.content)) + logger.warn('While parsing data from ComicVine, got exception: %s for data: %s' % (e, r.content)) + return + except Exception as e: + logger.warn('While parsing data from ComicVine, got exception: %s for data: %s' % (e, r.content)) return try: