diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2014-03-09 17:37:47 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2014-03-09 17:37:47 +0100 |
commit | d119a7150fa28c59d3b9e128cd158d67723f5931 (patch) | |
tree | 563027701cd0a7d6ce6614e958cba0647e474088 /modules | |
parent | 29328242db875656b13f8401948ebae4991a0df6 (diff) |
tracking: Handle HTTP errors in all tracking modules.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/tracking.py | 10 |
1 files changed, 8 insertions, 2 deletions
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) |