omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Media JSON to Media Model Error #1061

Closed xuanliao closed 8 years ago

xuanliao commented 8 years ago

tag_recent_media request media of a tag. the response data is {"pagination": {"next_min_id": "xxx", "deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead", "min_tag_id": "xxx"}, "meta": {"code": 200}, "data": [{"attribution": null, "tags": ["entertainment"], "type": "image", "location": null, "comments": {"count": 0}, "filter": "Normal", "created_time": "1479291465", "link": "https://www.instagram.com/p/", "likes": {"count": 0}, "images": {"low_resolution": {"url": "https://scontent.cdninstagram.com", "width": 320, "height": 320}, "thumbnail": {"url": "https://scontent.cdninstagram.com/", "width": 150, "height": 150}, "standard_resolution": {"url": "https://scontent.cdninstagram.com/", "width": 640, "height": 640}}, "users_in_photo": [], "caption": {"created_time": "1479291465", "text": "#entertainment", "from": {"username": "xuanpeng10", "profile_picture": "http://igcdn-photos-e-a.akamaihd.net", "id": "1441", "full_name": "fagfa"}, "id": "1786619283402415325113"}, "user_has_liked": false, "id": "5311161", "user": {"username": "aga", "profile_picture": "http://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xpa1", "id": "42515", "full_name": "fagag"}}]}

note: convert data to media model. in object_from_dictionary , pasrse "comments": {"count": 0}.

Code line 97 is new_media.comment_count = entry['comments']['count'] new_media.comments = [] for comment in entry['comments']['data']: new_media.comments.append(Comment.object_from_dictionary(comment))

but there's no data property in comments, so it raise no 'data' error, when parse data to media model.

We need to check if entry has_key('data') before entry['comments']['data']

xuanliao commented 8 years ago

parse the error project