KeyError: 'data' with Python Instagram API client

It appears that there is a bug in models.py. If you comment out line 99 and 100 in that file, the "sample app" will work, or at least appears to work. Obviously, this is not a "real" fix but it does show that it is not a problem with the sample Python program, or Instagram.

    Line 99  #  for comment in entry['comments']['data']:
    Line 100 #      new_media.comments.append(Comment.object_from_dictionary(comment))

+1 for answer from @forge

For docker users (as asked in a comment), fork the python-instagram repo, edit, and then pip install via github.

Or just use someone else's fork with the following line in your Dockerfile:

pip install git+https://github.com/zgazak/python-instagram

pythoninstagram-api docker


There is an open Github issue for this bug, a fix was sent, but it's not merged yet.

Add the one line fix to models.py on your installed package.

Open with sudo:

sudo vi /Library/Python/2.7/site-packages/instagram/models.py  # Use relevant python version 

On line 99, add this:

if "data" in entry["comments"]:

Correct indentation on next two lines:

       for comment in entry['comments']['data']: 
           new_media.comments.append(Comment.object_from_dictionary(comment))