From d119a7150fa28c59d3b9e128cd158d67723f5931 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 9 Mar 2014 17:37:47 +0100 Subject: tracking: Handle HTTP errors in all tracking modules. --- modules/tracking.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/tracking.py b/modules/tracking.py index 0597832..40e7e44 100644 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -176,7 +176,10 @@ class FedexModule(TrackingModule): code = self.splitcode(code) data = {'TrackPackagesRequest': {'appType': 'wtrk', 'uniqueKey': '', 'processingParameters': {'anonymousTransaction': True, 'clientId': 'WTRK', 'returnDetailedErrors': True, 'returnLocalizedDateTime': False}, 'trackingInfoList': [{'trackNumberInfo': {'trackingNumber': code, 'trackingQualifier': '', 'trackingCarrier': ''}}]}} url = 'https://www.fedex.com/trackingCal/track?' + urllib.urlencode({'data': json.dumps(data), 'action': 'trackpackages', 'locale': 'en_US', 'format': 'json', 'version': 99}) - u = urllib2.urlopen(url) + try: + u = urllib2.urlopen(url) + except urllib2.HTTPError as e: + raise PackageError(str(e)) data = u.read() u.close() for m in re.findall(r'(\\x[a-fA-F\d]{2})', data): @@ -215,7 +218,10 @@ class TollpostModule(TrackingModule): code = self.splitcode(code) url = 'http://www.tollpost.no/XMLServer/rest/trackandtrace' data = urllib.urlencode({'q': code}) - u = urllib2.urlopen(url, data) + try: + u = urllib2.urlopen(url, data) + except urllib2.HTTPError as e: + raise PackageError(str(e)) data = u.read() u.close() data = json.loads(data) -- cgit v1.2.3