Search code examples
python-2.7socrata

sodapy (Socrata) connection gaierror


I'm trying to make API calls on the SFPD dataset, available online (https://data.sfgov.org/Public-Safety/SFPD-Incidents-from-1-January-2003/tmnf-yvry) with the SodaPy library (https://github.com/xmunoz/sodapy). I just want to get the json data.

I've followed the example on GitHub as best as I can, but it's just not working. Here's the code:


from sodapy import Socrata

client = Socrata(api_endpoint, app_token)

dataset_id = 'tmnf-yvry'

data = client.get(dataset_id, limit=2)

Despite these attempts, I keep getting the following error:

ConnectionError: ('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known'))

Any clues on how to work through this?


Solution

  • If you are using credentials, etc, it needs to look something like this:

    from sodapy import Socrata
    
    cl = Socrata('data.colorado.gov','YOUR API KEY', username = 'YOUR USERNAME/EMAIL', password = 'YOUR PASSWORD')
    
    then something like:
    zx = cl.get('4eit-nuxn', limit=10, content_type='JSON', offset=0)
    

    then deal with what is there in zx. The above data is corporations in Colorado... to call data by fields you can try this for a down and dirty approach:

    for i in range(len(zx)):
        print string.capwords(zx[i]["entityname"]), string.capwords(zx[i]["principalcity"])
    

    In my case, at the end of processing I needed to explicitly set the var (zx, here) to None, then close the connection.

    Good luck!