OK, I have this code where i'm getting some json back from instagram's api....
instaINFO = requests.get("https://api.instagram.com/v1/media/%s?access_token=xyz" % instaMeID).json()
print instaINFO
#pdb.set_trace()
MSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTi me, 'profilePIC': instaINFO['data']['user']['profile_picture'],'userNAME': instaINFO[ 'data']['user']['username'], 'msgBODY': instaINFO['data']['caption']['text']}
but sometimes
instaINFO['data']['caption']['text']
might not have any data. and I get this back.
MSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTime,
'profilePIC': instaINFO['data']['user']['profile_picture'],'userNAME':
instaINFO['data']['user']['username'], 'msgBODY': instaINFO['data']['caption']
['text']}
TypeError: 'NoneType' object is not subscriptable
error checking or defensive coding is not my speciality... So how do I make the code pass if a json value = None
I've tried to do this but to no avail...
if instaINFO['data']['caption']['text'] == None:
pass
datakey empty or thecaptionkey?Nonesingleton should not be done with==but withis.