diff --git a/src/eircode/address.py b/src/eircode/address.py index f424246..e19ac8f 100644 --- a/src/eircode/address.py +++ b/src/eircode/address.py @@ -6,7 +6,7 @@ from eircode.logging import logger from eircode.eircode import Eircode -from eircode.constants import IDENTITY_URL_PATH, EIRCODE_FINDER_URL_PATH +from eircode.constants import IDENTITY_URL_PATH, EIRCODE_FINDER_URL_PATH, HEADERS from eircode.proxy import proxy @@ -96,7 +96,8 @@ def set(self, throw_ex=True, reverse=False): return else: - identity_response = requests.get(IDENTITY_URL_PATH).json() + + identity_response = requests.get(IDENTITY_URL_PATH, headers=HEADERS).json() params = { "key": identity_response["key"], "address": self.input_address, @@ -106,7 +107,7 @@ def set(self, throw_ex=True, reverse=False): } try: - finder_response = requests.get(EIRCODE_FINDER_URL_PATH, params=params) + finder_response = requests.get(EIRCODE_FINDER_URL_PATH, params=params, headers=HEADERS) except Exception as ex: if throw_ex: raise ex @@ -196,7 +197,7 @@ def eircode_data(self): if self.proxy: data = proxy.get(self.link).json() else: - data = requests.get(self.link).json() + data = requests.get(self.link, headers=HEADERS).json() if data.get("error", {}).get("code", None) == 403: raise ValueError(data["error"]["text"]) diff --git a/src/eircode/constants.py b/src/eircode/constants.py index 879af34..0b21cb9 100644 --- a/src/eircode/constants.py +++ b/src/eircode/constants.py @@ -8,7 +8,7 @@ IDENTITY_URL_PATH = "https://api-finder.eircode.ie/Latest/findergetidentity" EIRCODE_FINDER_URL_PATH = "https://api-finder.eircode.ie/Latest/finderfindaddress" - +HEADERS = {'User-Agent': 'Mozilla/5.0'} ROUTING_KEYS_TOWNS_MAP = { "A41": ["Ballyboughal"], "A42": ["Garristown"], diff --git a/src/eircode/proxy.py b/src/eircode/proxy.py index a9bfd56..6c463e8 100644 --- a/src/eircode/proxy.py +++ b/src/eircode/proxy.py @@ -5,6 +5,7 @@ import requests from requests_ip_rotator import ApiGateway +from eircode.constants import HEADERS from eircode.logging import logger @@ -30,6 +31,7 @@ def setup(self, force=False): self.session = requests.Session() self.session.mount(self.site, self.gateway) + self.session.headers = HEADERS self._is_setup = True diff --git a/test/test_proxy.py b/test/test_proxy.py index 718601f..cd8de13 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -1,5 +1,6 @@ from unittest import TestCase, skip +from eircode.constants import HEADERS from eircode.proxy import Proxy