aboutsummaryrefslogtreecommitdiffstats
path: root/tpblite/models/utils.py
diff options
context:
space:
mode:
authorMatt Lyon <matthewlyon18@gmail.com>2019-12-21 11:06:53 +0000
committerMatt Lyon <matthewlyon18@gmail.com>2019-12-21 11:06:53 +0000
commitc45b6ca3e82a5d10e14c31c4b7d0fdaf66fff933 (patch)
treeb1907ac15c689c9f441d5e3468935a2a330553c5 /tpblite/models/utils.py
parent26e7bacfcc1a86b703e92373b37ea7debdde8b34 (diff)
downloadtpb-lite-c45b6ca3e82a5d10e14c31c4b7d0fdaf66fff933.tar.gz
tpb-lite-c45b6ca3e82a5d10e14c31c4b7d0fdaf66fff933.tar.bz2
tpb-lite-c45b6ca3e82a5d10e14c31c4b7d0fdaf66fff933.zip
added better error handling for connection issuesv0.2.4
Diffstat (limited to 'tpblite/models/utils.py')
-rw-r--r--tpblite/models/utils.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tpblite/models/utils.py b/tpblite/models/utils.py
index 14c002f..1d6b351 100644
--- a/tpblite/models/utils.py
+++ b/tpblite/models/utils.py
@@ -1,5 +1,6 @@
import random
from urllib.request import Request, urlopen
+import urllib.error
from purl import URL as pURL
@@ -12,7 +13,10 @@ class QueryParser(object):
self.base_url = base_url
segments = ('search', query, str(page), str(order), str(category))
self.url = URL(base_url, segments)
- self.html_source = self._sendRequest()
+ try:
+ self.html_source = self._sendRequest()
+ except urllib.error.URLError:
+ raise ConnectionError('Could not establish connection wtih {}'.format(self.base_url))
def _sendRequest(self):
req = Request(self.url, headers=headers())
@@ -50,6 +54,4 @@ USER_AGENTS = (
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/60.0.3112.113 Safari/537.36',
-)
-
-### ==================== \ No newline at end of file
+) \ No newline at end of file