Switch to requests due to bug in Manticore client

This commit is contained in:
Mark Veidemanis 2022-09-07 07:20:30 +01:00
parent f35eb51aaf
commit f1cb539ca6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 12 additions and 5 deletions

View File

@ -14,7 +14,7 @@ from siphashc import siphash
from core import r from core import r
from core.lib.processing import annotate_results, filter_blacklisted, parse_results from core.lib.processing import annotate_results, filter_blacklisted, parse_results
from core.views import helpers from core.views import helpers
import requests
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -22,7 +22,7 @@ def initialise_manticore():
""" """
Initialise the Manticore client Initialise the Manticore client
""" """
configuration = manticoresearch.Configuration(host="http://monolith-db-1:9308") configuration = manticoresearch.Configuration(host=settings.MANTICORE_URL)
api_client = manticoresearch.ApiClient(configuration) api_client = manticoresearch.ApiClient(configuration)
api_instance = manticoresearch.SearchApi(api_client) api_instance = manticoresearch.SearchApi(api_client)
@ -83,9 +83,12 @@ def run_query(client, user, search_query):
response["took"] = time_took_rounded response["took"] = time_took_rounded
response["cache"] = True response["cache"] = True
return response return response
response = client.search(search_query) #response = client.search(search_query)
print("PRERESP", response) response = requests.post(f"{settings.MANTICORE_URL}/json/search", json=search_query)
response = response.to_dict() response = ujson.loads(response.text)
if "error" in response and len(response.keys()) == 1:
return response
#response = response.to_dict()
print("RESP", response) print("RESP", response)
if "took" in response: if "took" in response:
if response["took"] is None: if response["took"] is None:
@ -326,6 +329,10 @@ def query_results(
message_class = "danger" message_class = "danger"
return {"message": message, "class": message_class} return {"message": message, "class": message_class}
# results = results.to_dict() # results = results.to_dict()
if "error" in results:
message = results["error"]
message_class = "danger"
return {"message": message, "class": message_class}
results_parsed = parse_results(results) results_parsed = parse_results(results)
if annotate: if annotate:
annotate_results(results_parsed) annotate_results(results_parsed)