Skip to content

Commit dd1b122

Browse files
committed
Fix issue within economics returning a 403 error, fixing #162
1 parent a8ceb1a commit dd1b122

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

financetoolkit/economics/oecd_model.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
__docformat__ = "google"
44

5+
from io import StringIO
6+
57
import pandas as pd
8+
import requests
69

710
# pylint: disable=too-many-lines
811

@@ -199,7 +202,18 @@ def collect_oecd_data(oecd_data_string: str, period_code: str) -> pd.DataFrame:
199202
Returns:
200203
pd.DataFrame: A DataFrame containing the data from the OECD API.
201204
"""
202-
oecd_data = pd.read_csv(f"{BASE_URL}{oecd_data_string}{EXTENSIONS}")
205+
headers = {
206+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
207+
"AppleWebKit/537.36 (KHTML, like Gecko) "
208+
"Chrome/58.0.3029.110 Safari/537.3"
209+
}
210+
response = requests.get(
211+
f"{BASE_URL}{oecd_data_string}{EXTENSIONS}", headers=headers, timeout=300
212+
)
213+
214+
response.raise_for_status()
215+
216+
oecd_data = pd.read_csv(StringIO(response.text))
203217

204218
oecd_data["REF_AREA"] = oecd_data["REF_AREA"].replace(CODE_TO_COUNTRY)
205219

0 commit comments

Comments
 (0)