From aed206834224701d7ba0b311c54c5f3d3fffa38b Mon Sep 17 00:00:00 2001 From: cebtenzzre Date: Wed, 11 Oct 2023 18:11:28 -0400 Subject: [PATCH] python: always check status code of HTTP responses (#1502) --- gpt4all-bindings/python/gpt4all/gpt4all.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gpt4all-bindings/python/gpt4all/gpt4all.py b/gpt4all-bindings/python/gpt4all/gpt4all.py index 79d06f27..fc801782 100644 --- a/gpt4all-bindings/python/gpt4all/gpt4all.py +++ b/gpt4all-bindings/python/gpt4all/gpt4all.py @@ -113,7 +113,10 @@ class GPT4All: Returns: Model list in JSON format. """ - return requests.get("https://gpt4all.io/models/models2.json").json() + resp = requests.get("https://gpt4all.io/models/models2.json") + if resp.status_code != 200: + raise ValueError(f'Request failed: HTTP {resp.status_code} {resp.reason}') + return resp.json() @staticmethod def retrieve_model( @@ -215,6 +218,9 @@ class GPT4All: download_url = get_download_url(model_filename) response = requests.get(download_url, stream=True) + if response.status_code != 200: + raise ValueError(f'Request failed: HTTP {response.status_code} {response.reason}') + total_size_in_bytes = int(response.headers.get("content-length", 0)) block_size = 2**20 # 1 MB