From b8863b0be8b5169a5db0896a6fe5b164766912c7 Mon Sep 17 00:00:00 2001 From: Alex Parsons Date: Fri, 1 Nov 2024 09:31:07 +0000 Subject: [PATCH] Check agent exists --- src/parl_register_interests/official_data.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/parl_register_interests/official_data.py b/src/parl_register_interests/official_data.py index d9b3cfc..44173a2 100644 --- a/src/parl_register_interests/official_data.py +++ b/src/parl_register_interests/official_data.py @@ -153,8 +153,10 @@ def download_reg_on_date(register_date: date, force: bool = False): if not force and dest_folder.exists(): return - # use MYSOC_USER_AGENT env var to identify ourselves - headers = {"User-Agent": os.environ.get("MYSOC_USER_AGENT", "")} + user_agent = os.environ.get("MYSOC_USER_AGENT") + if not user_agent: + raise ValueError("Please set the MYSOC_USER_AGENT environment variable") + headers = {"User-Agent": user_agent} print(f"Downloading {url} to {zip_path}") with httpx.Client() as client: response = client.get(url, headers=headers)