Skip to content

Commit 31ec49b

Browse files
committed
implements workaround for missing cert files
1 parent 5529b1f commit 31ec49b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
setuptools~=49.2.0
12
requests==2.24.0
3+
certifi==2020.6.20

uk_covid19/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
__copyright__ = "Copyright (c) 2020, Public Health England"
3434
__description__ = "SDK for the COVID-19 API (Coronavirus Dashboard in the UK)"
3535
__license__ = "MIT"
36-
__version__ = "1.1.2"
36+
__version__ = "1.1.3"
3737
__url__ = "https://coronavirus.data.gov.uk/"
3838
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939

uk_covid19/api_interface.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
# 3rd party:
1313
from requests import request, Response
14+
import certifi
1415

1516
# Internal:
16-
from .utils import save_data
17+
from uk_covid19.utils import save_data
1718

1819
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1920

@@ -32,7 +33,6 @@ class Cov19API:
3233
------------
3334
Interface to access the API service for COVID-19 data in the United Kingdom.
3435
"""
35-
3636
endpoint = "https://api.coronavirus.data.gov.uk/v1/data"
3737
_valid_formats = [
3838
"csv",
@@ -163,7 +163,8 @@ def head(self):
163163
"""
164164
api_params = self.api_params
165165

166-
with request("HEAD", self.endpoint, params=api_params) as response:
166+
with request("HEAD", self.endpoint, params=api_params,
167+
verify=certifi.where()) as response:
167168
response.raise_for_status()
168169
return response.headers
169170

@@ -189,7 +190,7 @@ def options():
189190
...
190191
}
191192
"""
192-
with request("OPTIONS", Cov19API.endpoint) as response:
193+
with request("OPTIONS", Cov19API.endpoint, verify=certifi.where()) as response:
193194
response.raise_for_status()
194195
return response.json()
195196

@@ -220,21 +221,22 @@ def _get(self, format_as: str) -> Iterator[Response]:
220221
})
221222

222223
while True:
223-
response = request("GET", self.endpoint, params=api_params)
224-
225-
if response.status_code >= HTTPStatus.BAD_REQUEST:
226-
raise RuntimeError(f'Request failed: {response.text}')
227-
elif response.status_code == HTTPStatus.NO_CONTENT:
228-
self.total_pages = api_params["page"] - 1
229-
break
224+
with request("GET", self.endpoint, params=api_params,
225+
verify=certifi.where()) as response:
226+
if response.status_code >= HTTPStatus.BAD_REQUEST:
227+
raise RuntimeError(f'Request failed: {response.text}')
228+
if response.status_code == HTTPStatus.NO_CONTENT:
229+
self.total_pages = api_params["page"] - 1
230+
break
230231

231-
self._last_update = response.headers["Last-Modified"]
232+
self._last_update = response.headers["Last-Modified"]
232233

233-
yield response
234+
yield response
234235

235236
api_params["page"] += 1
236237

237-
def get_json(self, save_as: Union[str, None] = None, as_string: bool = False) -> Union[dict, str]:
238+
def get_json(self, save_as: Union[str, None] = None,
239+
as_string: bool = False) -> Union[dict, str]:
238240
"""
239241
Provides full data (all pages) in JSON.
240242
@@ -446,7 +448,7 @@ def get_csv(self, save_as=None) -> str:
446448
return resp
447449

448450
def __str__(self):
449-
resp = "COVID-19 API\nCurrent parameters: \n"
451+
resp = "COVID-19 in the UK - API Service\nCurrent parameters: \n"
450452
return resp + dumps(self.api_params, indent=4)
451453

452454
__repr__ = __str__

0 commit comments

Comments
 (0)