Skip to content

Commit

Permalink
hotfix: backend tests failing due to Nominatim server error:403
Browse files Browse the repository at this point in the history
Causing to fail with requests.exceptions.HTTPError: 403 Client Error: Forbidden for url. Solved with appropriate User agent headers
  • Loading branch information
mahesh-naxa authored and dakotabenjamin committed Mar 26, 2024
1 parent 2aa429c commit ea0b579
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,15 @@ def set_country_info(self):
url = "{0}/reverse?format=jsonv2&lat={1}&lon={2}&accept-language=en".format(
current_app.config["OSM_NOMINATIM_SERVER_URL"], lat, lng
)
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/58.0.3029.110 Safari/537.3"
)
}
try:
response = requests.get(url)
response = requests.get(url, headers=headers)
response.raise_for_status()
country_info = response.json() # returns a dict
if country_info["address"].get("country") is not None:
Expand Down

0 comments on commit ea0b579

Please sign in to comment.