Skip to content

Commit

Permalink
[FIX] base_geolocalize: access blocked by OpenStreetMap
Browse files Browse the repository at this point in the history
The geolocation service from OpenStreetMap will not be unblocked until a
'meaningful' and identical user-agent added in the request.

opw-2221857

X-original-commit: 9018039
  • Loading branch information
qho-odoo authored and nim-odoo committed Apr 1, 2020
1 parent 806edb3 commit 00f9b90
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addons/base_geolocalize/models/base_geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ def _call_openstreetmap(self, addr, **kw):
return None
url = 'https://nominatim.openstreetmap.org/search'
try:
result = requests.get(url, {'format': 'json', 'q': addr}).json()
headers = {'User-Agent': 'Odoo (http://www.odoo.com/contactus)'}
response = requests.get(url, headers=headers, params={'format': 'json', 'q': addr})
_logger.info('openstreetmap nominatim service called')
if response.status_code != 200:
_logger.error('Request to openstreetmap failed.\nCode: %s\nContent: %s' % (response.status_code, response.content))
result = response.json()
except Exception as e:
self._raise_query_error(e)
geo = result[0]
Expand Down

0 comments on commit 00f9b90

Please sign in to comment.