# Python 3 standard library. OSRM_API_KEY=... python3 platform-starter.py
# Live geocoding; normal credits apply. No automatic retry of paid requests.
import json, os, urllib.request, urllib.error
key = os.environ.get('OSRM_API_KEY')
if not key:
    raise SystemExit('Set OSRM_API_KEY')
request = urllib.request.Request('https://osrmroute.com/api/1/geocode?q=Baku&limit=1', headers={'Authorization': 'Bearer ' + key})
try:
    with urllib.request.urlopen(request, timeout=20) as response:
        print(json.dumps({'request_id': response.headers.get('X-Request-Id'), 'result': json.load(response)}, indent=2))
except urllib.error.HTTPError as error:
    # Do not print keys, full URLs or request payloads in diagnostic logs.
    raise SystemExit(json.dumps({'status': error.code, 'request_id': error.headers.get('X-Request-Id')}))
