sodapy (Socrata) 连接 gaierror
sodapy (Socrata) connection gaierror
我正在尝试对 SFPD 数据集进行 API 调用,可在线获取 (https://data.sfgov.org/Public-Safety/SFPD-Incidents-from-1-January-2003/tmnf-yvry) with the SodaPy library (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'))
关于如何解决这个问题的任何线索?
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'}]
如果您使用凭据等,它需要看起来像这样:
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)
然后处理zx里面的东西。以上数据是科罗拉多州的公司...按字段调用数据你可以试试这个卑鄙的方法:
for i in range(len(zx)):
print string.capwords(zx[i]["entityname"]), string.capwords(zx[i]["principalcity"])
在我的例子中,在处理结束时我需要明确地将 var(zx,这里)设置为 None,然后关闭连接。
祝你好运!
我正在尝试对 SFPD 数据集进行 API 调用,可在线获取 (https://data.sfgov.org/Public-Safety/SFPD-Incidents-from-1-January-2003/tmnf-yvry) with the SodaPy library (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'))
关于如何解决这个问题的任何线索?
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'}]
如果您使用凭据等,它需要看起来像这样:
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)
然后处理zx里面的东西。以上数据是科罗拉多州的公司...按字段调用数据你可以试试这个卑鄙的方法:
for i in range(len(zx)):
print string.capwords(zx[i]["entityname"]), string.capwords(zx[i]["principalcity"])
在我的例子中,在处理结束时我需要明确地将 var(zx,这里)设置为 None,然后关闭连接。
祝你好运!