In [1]:
import sys
import requests

q = 'kota sukabumi'
r = requests.get('http://api.geonames.org/searchJSON',
    params={'q': q, 'username': 'ceefour'})
r


Out[1]:
<Response [200]>

In [2]:
# HTTP status code:
r.status_code


Out[2]:
200

In [3]:
# HTTP response headers
r.headers


Out[3]:
{'Date': 'Tue, 19 Sep 2017 07:13:02 GMT', 'Server': 'Apache/2.4.6 (CentOS) mod_jk/1.2.41 OpenSSL/1.0.1e-fips', 'Cache-Control': 'no-cache', 'Access-Control-Allow-Origin': '*', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json;charset=UTF-8'}

In [4]:
# Response body
r.text


Out[4]:
'{"totalResultsCount":2,"geonames":[{"adminCode1":"30","lng":"106.92667","geonameId":1626381,"toponymName":"Sukabumi","countryId":"1643084","fcl":"P","population":276414,"countryCode":"ID","name":"Sukabumi","fclName":"city, village,...","countryName":"Indonesia","fcodeName":"populated place","adminName1":"West Java","lat":"-6.91806","fcode":"PPL"},{"adminCode1":"30","lng":"106.93333","geonameId":1626379,"toponymName":"Kota Sukabumi","countryId":"1643084","fcl":"A","population":311628,"countryCode":"ID","name":"Kota Sukabumi","fclName":"country, state, region,...","countryName":"Indonesia","fcodeName":"second-order administrative division","adminName1":"West Java","lat":"-6.95","fcode":"ADM2"}]}'

In [ ]: