diff --git a/app/request.py b/app/request.py index 71f4e9b..6d25224 100644 --- a/app/request.py +++ b/app/request.py @@ -274,14 +274,19 @@ class Request: # Make sure that the tor connection is valid, if enabled if self.tor: - tor_check = requests.get('https://check.torproject.org/', - proxies=self.proxies, headers=headers) - self.tor_valid = 'Congratulations' in tor_check.text - - if not self.tor_valid: + try: + tor_check = requests.get('https://check.torproject.org/', + proxies=self.proxies, headers=headers) + self.tor_valid = 'Congratulations' in tor_check.text + + if not self.tor_valid: + raise TorError( + "Tor connection succeeded, but the connection could " + "not be validated by torproject.org", + disable=True) + except ConnectionError: raise TorError( - "Tor connection succeeded, but the connection could not " - "be validated by torproject.org", + "Error raised during Tor connection validation", disable=True) response = requests.get( diff --git a/app/utils/search.py b/app/utils/search.py index ee092fe..7ee191c 100644 --- a/app/utils/search.py +++ b/app/utils/search.py @@ -140,10 +140,8 @@ class Search: html_soup = content_filter.view_image(html_soup) # Indicate whether or not a Tor connection is active - tor_banner = bsoup('', 'html.parser') if g.user_request.tor_valid: - tor_banner = bsoup(TOR_BANNER, 'html.parser') - html_soup.insert(0, tor_banner) + html_soup.insert(0, bsoup(TOR_BANNER, 'html.parser')) if self.feeling_lucky: return get_first_link(html_soup)