In [31]:
import sys
import requests

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


Out[31]:
<Response [200]>

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


Out[32]:
200

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


Out[33]:
{'Date': 'Fri, 15 Sep 2017 14:55:37 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': '*', 'Keep-Alive': 'timeout=5, max=100', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json;charset=UTF-8'}

In [34]:
# Response body
r.text


Out[34]:
'{"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"}]}'