AlienVault-OTX / OTX-Python-SDK

The Python SDK for AlienVault OTX
Other
357 stars 162 forks source link

List index out of range from mtime #8

Open affvei opened 8 years ago

affvei commented 8 years ago
>>> mtime = (datetime.now() - timedelta(days=1)).isoformat()
>>> mtime
'2015-12-09T14:33:11.722751'
>>> events = otx.getevents_since(mtime)
>>> json_normalize(events)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pandas/io/json.py", line 684, in json_normalize
    if any([isinstance(x, dict) for x in compat.itervalues(data[0])]):
IndexError: list index out of range
bsmartt13 commented 8 years ago

The issue here is panda's json_normalize, which somewhat oddly raises IndexError for empty lists:

>>> json_normalize([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bsmartt/Resources/tmp/ott/lib/python2.7/site-packages/pandas/io/json.py", line 707, in json_normalize
    if any([isinstance(x, dict) for x in compat.itervalues(data[0])]):
IndexError: list index out of range

I suggest we update the notebook like this:

if events:
    json_normalize(events)

I haven't been able to preview this on github yet it might be sufficient though: https://github.com/bsmartt13/OTX-Python-SDK/commit/6b230563d1cc3811ef280e60b08bce2d342357a6