Catch connection error during Tor validation step
Validation of the Tor connection occasionally fails with a ConnectionError from requests, which was previously uncaught. This is now handled appropriately (error message shown and connection dropped). Fixes #532main
parent
3f40a6c485
commit
e93507f148
|
@ -274,14 +274,19 @@ class Request:
|
||||||
|
|
||||||
# Make sure that the tor connection is valid, if enabled
|
# Make sure that the tor connection is valid, if enabled
|
||||||
if self.tor:
|
if self.tor:
|
||||||
|
try:
|
||||||
tor_check = requests.get('https://check.torproject.org/',
|
tor_check = requests.get('https://check.torproject.org/',
|
||||||
proxies=self.proxies, headers=headers)
|
proxies=self.proxies, headers=headers)
|
||||||
self.tor_valid = 'Congratulations' in tor_check.text
|
self.tor_valid = 'Congratulations' in tor_check.text
|
||||||
|
|
||||||
if not self.tor_valid:
|
if not self.tor_valid:
|
||||||
raise TorError(
|
raise TorError(
|
||||||
"Tor connection succeeded, but the connection could not "
|
"Tor connection succeeded, but the connection could "
|
||||||
"be validated by torproject.org",
|
"not be validated by torproject.org",
|
||||||
|
disable=True)
|
||||||
|
except ConnectionError:
|
||||||
|
raise TorError(
|
||||||
|
"Error raised during Tor connection validation",
|
||||||
disable=True)
|
disable=True)
|
||||||
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
|
|
@ -140,10 +140,8 @@ class Search:
|
||||||
html_soup = content_filter.view_image(html_soup)
|
html_soup = content_filter.view_image(html_soup)
|
||||||
|
|
||||||
# Indicate whether or not a Tor connection is active
|
# Indicate whether or not a Tor connection is active
|
||||||
tor_banner = bsoup('', 'html.parser')
|
|
||||||
if g.user_request.tor_valid:
|
if g.user_request.tor_valid:
|
||||||
tor_banner = bsoup(TOR_BANNER, 'html.parser')
|
html_soup.insert(0, bsoup(TOR_BANNER, 'html.parser'))
|
||||||
html_soup.insert(0, tor_banner)
|
|
||||||
|
|
||||||
if self.feeling_lucky:
|
if self.feeling_lucky:
|
||||||
return get_first_link(html_soup)
|
return get_first_link(html_soup)
|
||||||
|
|
Loading…
Reference in New Issue