Commit 1d3379c7d1b9f925e639bbfeaf8ae78107540e75
1 parent
d0f0ebd9
Exists in
master
and in
39 other branches
Temporary work around to access solr behind proxy
This fix won't work well on production environments since another request might occour while socket.socket still configured to use proxy. This is not a big deal because proxy here is meant only for test porpouses and more over solrutils.py will be replaced by haystack.
Showing
1 changed file
with
10 additions
and
2 deletions
Show diff stats
src/colab/deprecated/solrutils.py
... | ... | @@ -13,6 +13,10 @@ from dateutil.parser import parse as parse_timestamp |
13 | 13 | from django.conf import settings |
14 | 14 | |
15 | 15 | from super_archives.models import EmailAddress |
16 | +from . import socks | |
17 | + | |
18 | + | |
19 | +DEFAULT_SOCKET = socket.socket | |
16 | 20 | |
17 | 21 | |
18 | 22 | def build_query(user_query, filters=None): |
... | ... | @@ -181,7 +185,6 @@ def select(query, results_per_page=None, page_number=None, sort=None, fields=Non |
181 | 185 | # if the solr server is behind a firewall. |
182 | 186 | socks_server = getattr(settings, "SOCKS_SERVER", None) |
183 | 187 | if socks_server: |
184 | - import socks | |
185 | 188 | logging.debug('Socks enabled: %s:%s', settings.SOCKS_SERVER, |
186 | 189 | settings.SOCKS_PORT) |
187 | 190 | |
... | ... | @@ -196,6 +199,8 @@ def select(query, results_per_page=None, page_number=None, sort=None, fields=Non |
196 | 199 | except socket.error as err: |
197 | 200 | solr_response = None |
198 | 201 | logging.exception(err) |
202 | + finally: | |
203 | + reset_defaultproxy() | |
199 | 204 | |
200 | 205 | if solr_response and solr_response.status == 200: |
201 | 206 | #TODO: Log error connecting to solr |
... | ... | @@ -266,4 +271,7 @@ def count_types(sample=100, filters=None): |
266 | 271 | |
267 | 272 | return type_count |
268 | 273 | |
269 | - | |
274 | + | |
275 | +def reset_defaultproxy(): | |
276 | + socket.socket = DEFAULT_SOCKET | |
277 | + socks._defaultproxy = None | ... | ... |