好的,我有这段代码,我从 instagram 的 api 中获取了一些 json ......
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']}
但是有时
instaINFO['data']['caption']['text']
可能没有任何数据。我得到了这个。
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
错误检查或防御性编码不是我的专长......那么如果 json 值 = 无,我该如何让代码通过
我试过这样做,但无济于事......
if instaINFO['data']['caption']['text'] == None:
pass