NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello,

I'm using python (jupyter notebook) to get data of hospitals in Bali area, Indonesia. Here is my code and query:

import pandas as pd
import requests
import json
overpass_api = "http://overpass-api.de/api/interpreter"

query_hospital = """
[out:json];
{{geocodeArea:'Provinsi Bali'}}->.searchArea;
node[amenity='hospital'](area.searchArea);
out;
"""

response_hospital = requests.get(overpass_api, params={'data':query_hospital})

but when I run the next code,

data_hospital = response_hospital.json()

it returns error JSONDecodeError: Expecting value: line 1 column 1 (char 0)

the query works well in Overpass Turbo but when I put in notebook, it returns error.

Thanks for the help.

asked 08 May '22, 15:05

salmiah-ls's gravatar image

salmiah-ls
11113
accept rate: 0%

edited 09 May '22, 23:43

check the status code of the query, it's returning 400. The .text says: Error: line 2: parse error: Unknown type "{", Error: line 2: parse error: An empty query is not allowed and Error: line 2: parse error: ';' expected - '{' found.

(08 May '22, 20:31) Marcos Dione

yes, I have the same thought. looks like python can't parse that double curly braces {{ }}.

I wonder if there is way to modify the query in OSM so it can return the same result but without that double curly braces.

(09 May '22, 05:53) salmiah-ls

I've found the solution.

I modify the query so I doesn't include the double curly braces {{ }} anymore, which seems python can't parse. Here is my new query:

query_hospital = """
[out:json];
area[name=Bali];
node[amenity='hospital'](area);
out;
"""

or if we use area name in local language:

query_hospital = """
[out:json];
area['name:id'='Provinsi Bali'];
node[amenity='hospital'](area);
out;
"""

the query returns same result and python can parse it now.

permanent link

answered 09 May '22, 23:41

salmiah-ls's gravatar image

salmiah-ls
11113
accept rate: 0%

edited 09 May '22, 23:57

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×147
×78
×28
×3

question asked: 08 May '22, 15:05

question was seen: 1,178 times

last updated: 09 May '22, 23:57

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum