diff --git a/watttime/api.py b/watttime/api.py index bc5b18c..4b4c399 100644 --- a/watttime/api.py +++ b/watttime/api.py @@ -24,6 +24,7 @@ def __init__(self, username: Optional[str] = None, password: Optional[str] = Non """ self.username = username or os.getenv("WATTTIME_USER") self.password = password or os.getenv("WATTTIME_PASSWORD") + self.certificate_location = os.getenv("PEM_CERTIFICATE") self.token = None self.token_valid_until = None @@ -39,6 +40,7 @@ def _login(self): rsp = requests.get( url, auth=requests.auth.HTTPBasicAuth(self.username, self.password), + verify=self.certificate_location, timeout=20, ) rsp.raise_for_status() @@ -126,7 +128,7 @@ def register(self, email: str, organization: Optional[str] = None) -> None: "org": organization, } - rsp = requests.post(url, json=params, timeout=20) + rsp = requests.post(url, json=params, verify=self.certificate_location, timeout=20) rsp.raise_for_status() print( f"Successfully registered {self.username}, please check {email} for a verification email" @@ -163,7 +165,7 @@ def region_from_loc( "longitude": str(longitude), "signal_type": signal_type, } - rsp = requests.get(url, headers=headers, params=params) + rsp = requests.get(url, headers=headers, params=params, verify=self.certificate_location) if not rsp.ok: if rsp.status_code == 404: # here we specifically cannot find a location that was provided @@ -219,7 +221,7 @@ def get_historical_jsons( for c in chunks: params["start"], params["end"] = c - rsp = requests.get(url, headers=headers, params=params) + rsp = requests.get(url, headers=headers, params=params, verify=self.certificate_location) try: rsp.raise_for_status() j = rsp.json() @@ -325,7 +327,7 @@ def get_access_json(self) -> Dict: self._login() url = "{}/v3/my-access".format(self.url_base) headers = {"Authorization": "Bearer " + self.token} - rsp = requests.get(url, headers=headers) + rsp = requests.get(url, headers=headers, verify=self.certificate_location) rsp.raise_for_status() return rsp.json() @@ -409,7 +411,7 @@ def get_forecast_json( url = "{}/v3/forecast".format(self.url_base) headers = {"Authorization": "Bearer " + self.token} - rsp = requests.get(url, headers=headers, params=params) + rsp = requests.get(url, headers=headers, params=params, verify=self.certificate_location) rsp.raise_for_status() return rsp.json() @@ -488,7 +490,7 @@ def get_historical_forecast_json( for c in chunks: params["start"], params["end"] = c - rsp = requests.get(url, headers=headers, params=params) + rsp = requests.get(url, headers=headers, params=params, verify=self.certificate_location) try: rsp.raise_for_status() j = rsp.json() @@ -565,6 +567,6 @@ def get_maps_json( url = "{}/v3/maps".format(self.url_base) headers = {"Authorization": "Bearer " + self.token} params = {"signal_type": signal_type} - rsp = requests.get(url, headers=headers, params=params) + rsp = requests.get(url, headers=headers, params=params, verify=self.certificate_location) rsp.raise_for_status() return rsp.json()