Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/eircode/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion src/eircode/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 2 additions & 0 deletions src/eircode/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from requests_ip_rotator import ApiGateway

from eircode.constants import HEADERS
from eircode.logging import logger


Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/test_proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestCase, skip

from eircode.constants import HEADERS
from eircode.proxy import Proxy


Expand Down