# This cell should run successfully if you have a string set up to represent your census key try: import settings assert type(settings.CENSUS_KEY) == str or type(settings.CENSUS_KEY) == unicode except Exception as e: print "error in importing settings to get at settings.CENSUS_KEY", e # let's figure out a bit about the us module, in particular, us.states # https://github.com/unitedstates/python-us from us import states assert states.CA.fips == u'06' # set up your census object # example from https://github.com/sunlightlabs/census from census import Census from us import states c = Census(settings.CENSUS_KEY) for (i, state) in enumerate(states.STATES): print i, state.name, state.fips import requests # get the total population of all states url = "http://api.census.gov/data/2010/sf1?key={key}&get=P0010001,NAME&for=state:*".format(key=settings.CENSUS_KEY) r = requests.get(url) # FILL IN WITH YOUR CODE c.sf1.get(('NAME', 'P0010001'), {'for': 'state:%s' % states.CA.fips}) "population of California: {0}".format( int(c.sf1.get(('NAME', 'P0010001'), {'for': 'state:%s' % states.CA.fips})[0]['P0010001']))