aboutsummaryrefslogtreecommitdiffstats
path: root/tpblite/models/utils.py
diff options
context:
space:
mode:
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