From b7d4dfcbe5a217060fc1434614d2d3e98afdbbba Mon Sep 17 00:00:00 2001 From: Xudong Han Date: Thu, 18 Apr 2024 10:13:08 +0800 Subject: [PATCH] valid serper response status code --- factcheck/core/Retriever/SerperEvidenceRetrieve.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/factcheck/core/Retriever/SerperEvidenceRetrieve.py b/factcheck/core/Retriever/SerperEvidenceRetrieve.py index 97c354d..657f9bc 100644 --- a/factcheck/core/Retriever/SerperEvidenceRetrieve.py +++ b/factcheck/core/Retriever/SerperEvidenceRetrieve.py @@ -185,8 +185,12 @@ def _request_serper_api(self, questions): questions_data = [{"q": question, "autocorrect": False} for question in questions] payload = json.dumps(questions_data) response = None - try: - response = requests.request("POST", url, headers=headers, data=payload) - except Exception as e: - logger.info(f"Warning, Serper API error: {e}.") - return response + response = requests.request("POST", url, headers=headers, data=payload) + + if response.status_code == 200: + return response + elif response.status_code == 403: + raise Exception("Failed to authenticate. Check your API key.") + else: + raise Exception(f"Error occurred: {response.text}") +