i'm trying retrieve response ip-api.com ip ranges. want store data in aerospike i'm having errors.
here python script
# import module __future__ import print_function import aerospike import urllib2 config = { 'hosts': [ ('127.0.0.1', 3000) ] } try: client = aerospike.client(config).connect() except: import sys print("failed connect cluster with", config['hosts']) sys.exit(1) key = ('ip', 'hit', 'trial') try: in range(0,255): j in range(0,255): k in range(0,255): l in range(0,255): if not((i == 198 , j == 168) or (i == 172 , j > 15 , j < 32) or (i == 10)): response = urllib2.urlopen('http://ip-api.com/json/'+str(i)+'.'+str(j)+'.'+str(k)+'.'+str(l)) html = response.read() client.put(key, html) except exception e: import sys print("error: {0}".format(e), file=sys.stderr) client.close()
i'm new python aerospike, infact no-sql databases. appreciated.
all code aerospike perspective right, except want change
html = response.read() client.put(key, html)
to
import json client.put(key, json.load(response))
the response json string needs converted json object
Comments
Post a Comment