sodapy(Socrata)连接gaierror

时间:2016-02-25 06:20:08

标签: python-2.7 socrata

我尝试在SFPD数据集上进行API调用,可以在线(https://data.sfgov.org/Public-Safety/SFPD-Incidents-from-1-January-2003/tmnf-yvry)使用SodaPy库(https://github.com/xmunoz/sodapy)。我只是想得到json数据。

我尽可能地遵循GitHub上的示例,但它只是不起作用。这是代码:

from sodapy import Socrata

client = Socrata(api_endpoint, app_token)

dataset_id = 'tmnf-yvry'

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

尽管有这些尝试,我仍然收到以下错误:

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

有关如何解决此问题的任何线索?

2 个答案:

答案 0 :(得分:1)

from sodapy import Socrata

client = Socrata('data.sfgov.org', None)

dataset_id = 'tmnf-yvry'

data = client.get(dataset_id, limit=2)
print data
{"stdout":"[{u'category': u'ASSAULT', u'dayofweek': u'Wednesday', u'incidntnum': u'050436712', u'time': u'04:00', u'descript': u'BATTERY', u'pddistrict': u'MISSION', u'y': u'37.7608878061245', u'location': {u'latitude': u'37.7608878061245', u'needs_recoding': False, u'human_address': u'{\"address\":\"\",\"city\":\"\",\"state\":\"\",\"zip\":\"\"}', u'longitude': u'-122.435002864271'}, u'address': u'18TH ST / CASTRO ST', u'date': u'2005-04-20T00:00:00', u'x': u'-122.435002864271', u'resolution': u'NONE', u'pdid': u'5043671204134'}, {u'category': u'LARCENY/THEFT', u'dayofweek': u'Sunday', u'incidntnum': u'080049078', u'time': u'18:00', u'descript': u'GRAND THEFT FROM A BUILDING', u'pddistrict': u'PARK', u'y': u'37.7622550270122', u'location': {u'latitude': u'37.7622550270122', u'needs_recoding': False, u'human_address': u'{\"address\":\"\",\"city\":\"\",\"state\":\"\",\"zip\":\"\"}', u'longitude': u'-122.446837820235'}, u'address': u'1100 Block of CLAYTON ST', u'date': u'2008-01-13T00:00:00', u'x': u'-122.446837820235', u'resolution': u'NONE', u'pdid': u'8004907806304'}]

答案 1 :(得分:0)

如果您使用凭据等,则需要看起来像这样:

error("Error Message") -- Throws at the current stack
error("Error Message",2) -- Throws to the caller
error("Error Message",3) -- Throws to the caller after that

然后处理zx中的内容。以上数据是科罗拉多州的公司......通过字段调用数据,您可以尝试使用这种方法进行简单而肮脏的方法:

local function aSimpleFunction(...)
    if pcall(function(...)
        string.format(...)
    end) == false then
       error("Function cannot format text",2)
    end

end

aSimpleFunction("An example function: %i",nil) --Error appears here 

在我的情况下,在处理结束时我需要将var(zx,here)显式设置为None,然后关闭连接。

祝你好运!