xmunoz / sodapy

Python client for the Socrata Open Data API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError: 'attachments' when calling 'download_attachments'

SamaaG opened this issue · comments

When calling 'download_attachments' I face a KeyError problem. Could someone help please.

from sodapy import Socrata

client = Socrata("sandbox.demo.socrata.com", None)
Warning: requests made without an app_token will be subject to strict throttling
limits.

client.get("nimj-3ivp", limit=2)
[{u'geolocation': {u'latitude': u'41.1085', u'needs_recoding': False, u'longitud
e': u'-117.6135'}, u'version': u'9', u'source': u'nn', u'region': u'Nevada', u'o
ccurred_at': u'2012-09-14T22:38:01', u'number_of_stations': u'15', u'depth': u'7
.60', u'magnitude': u'2.7', u'earthquake_id': u'00388610'}, {u'geolocation': {u'
latitude': u'34.525', u'needs_recoding': False, u'longitude': u'-118.1527'}, u'v
ersion': u'0', u'source': u'ci', u'region': u'Southern California', u'occurred_a
t': u'2012-09-14T22:14:45', u'number_of_stations': u'35', u'depth': u'10.60', u'
magnitude': u'1.5', u'earthquake_id': u'15215753'}]

client.download_attachments(dataset_identifier="nimj-3ivp", download_dir="~/
Desktop")
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\sodapy__init__.py", line 137, in download
_attachments
attachments = metadata['metadata']['attachments']
KeyError: 'attachments'

That dataset doesn't actually have any attachments, so there will be no attachments key in the metadata.