From 37929122a587e8d746ebb3eae3271acac247b80b Mon Sep 17 00:00:00 2001 From: Ashish Kulkarni Date: Fri, 2 Feb 2024 13:35:02 +0530 Subject: [PATCH 1/3] change timeout to seconds --- serpapi/serp_api_client.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/serpapi/serp_api_client.py b/serpapi/serp_api_client.py index f52075f..84cea95 100644 --- a/serpapi/serp_api_client.py +++ b/serpapi/serp_api_client.py @@ -9,12 +9,15 @@ class SerpApiClient(object): """SerpApiClient enables to query any search engines supported by SerpApi and parse the results. ```python from serpapi import GoogleSearch - search = SerpApiClient({ - "q": "Coffee", - "location": "Austin,Texas", - "engine": "google", - "api_key": "" - }) + search = SerpApiClient( + { + "q": "Coffee", + "location": "Austin,Texas", + "engine": "google", + "api_key": "", + }, + timeout = 60, + ) data = search.get_json() ``` @@ -24,7 +27,7 @@ class SerpApiClient(object): BACKEND = "https://serpapi.com" SERP_API_KEY = None - def __init__(self, params_dict, engine = None, timeout = 60000): + def __init__(self, params_dict, engine = None, timeout = 60): self.params_dict = params_dict self.engine = engine self.timeout = timeout @@ -47,7 +50,6 @@ def get_response(self, path = '/search'): url = None try: url, parameter = self.construct_url(path) - # print(url) response = requests.get(url, parameter, timeout=self.timeout) return response except requests.HTTPError as e: From caa9098cd26a84c83e3a2fdf1178769192080f78 Mon Sep 17 00:00:00 2001 From: Ashish Kulkarni Date: Fri, 2 Feb 2024 13:38:26 +0530 Subject: [PATCH 2/3] set timeout at GoogleSearch instantiation --- serpapi/google_search.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/serpapi/google_search.py b/serpapi/google_search.py index bf85638..d174858 100644 --- a/serpapi/google_search.py +++ b/serpapi/google_search.py @@ -4,12 +4,18 @@ class GoogleSearch(SerpApiClient): """GoogleSearch enables to search google and parse the result. ```python from serpapi import GoogleSearch - query = GoogleSearch({"q": "coffee", "location": "Austin,Texas"}) + query = GoogleSearch( + { + "q": "coffee", + "location": "Austin,Texas", + }, + timeout = 60, + ) data = query.get_json() ``` https://github.com/serpapi/google-search-results-python """ - def __init__(self, params_dict): - super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE) + def __init__(self, params_dict, timeout = 60): + super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE, timeout) From d1b2ae5b27ebcf11cff0453a864a51b67bde0ba5 Mon Sep 17 00:00:00 2001 From: Ashish Kulkarni Date: Fri, 2 Feb 2024 13:40:34 +0530 Subject: [PATCH 3/3] allow SSL verify flag (for GET request) to be set at search object instantiation --- serpapi/google_search.py | 5 +++-- serpapi/serp_api_client.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/serpapi/google_search.py b/serpapi/google_search.py index d174858..76dcd6e 100644 --- a/serpapi/google_search.py +++ b/serpapi/google_search.py @@ -10,6 +10,7 @@ class GoogleSearch(SerpApiClient): "location": "Austin,Texas", }, timeout = 60, + ssl_verify = True, ) data = query.get_json() ``` @@ -17,5 +18,5 @@ class GoogleSearch(SerpApiClient): https://github.com/serpapi/google-search-results-python """ - def __init__(self, params_dict, timeout = 60): - super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE, timeout) + def __init__(self, params_dict, timeout = 60, ssl_verify = True): + super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE, timeout, ssl_verify) diff --git a/serpapi/serp_api_client.py b/serpapi/serp_api_client.py index 84cea95..eef4a89 100644 --- a/serpapi/serp_api_client.py +++ b/serpapi/serp_api_client.py @@ -17,6 +17,7 @@ class SerpApiClient(object): "api_key": "", }, timeout = 60, + ssl_verify = True, ) data = search.get_json() ``` @@ -27,10 +28,11 @@ class SerpApiClient(object): BACKEND = "https://serpapi.com" SERP_API_KEY = None - def __init__(self, params_dict, engine = None, timeout = 60): + def __init__(self, params_dict, engine = None, timeout = 60, ssl_verify = True): self.params_dict = params_dict self.engine = engine self.timeout = timeout + self.ssl_verify = ssl_verify def construct_url(self, path = "/search"): self.params_dict['source'] = 'python' @@ -50,7 +52,7 @@ def get_response(self, path = '/search'): url = None try: url, parameter = self.construct_url(path) - response = requests.get(url, parameter, timeout=self.timeout) + response = requests.get(url, parameter, timeout=self.timeout, verify=self.ssl_verify) return response except requests.HTTPError as e: print("fail: " + url)