我正在努力访问下面更新对象的'from'中嵌套的'is\u bot'属性:
{'message': {'caption_entities': [],
'channel_chat_created': False,
'chat': {'first_name': 'Rodrigo Formighieri',
'id': 446924384,
'type': 'private',
'username': 'rodrigoformi'},
'date': 1516040454,
'delete_chat_photo': False,
'entities': [{'length': 7, 'offset': 0, 'type': 'bot_command'}],
'from': {'first_name': 'Rodrigo Formighieri',
'id': 446924384,
'is_bot': False,
'language_code': 'pt-BR',
'username': 'rodrigoformi'},
'group_chat_created': False,
'message_id': 145,
'new_chat_member': None,
'new_chat_members': [],
'new_chat_photo': [],
'photo': [],
'supergroup_chat_created': False,
'text': '/invite'},
'update_id': 241263441}
我尝试过:
update.get('message',{}).get('from',{}).is_bot
此up返回AttributeError:'Message'对象没有属性'get'
update["message"]["from"]["is_bot"]
最后一个返回TypeError:'NoneType'对象不可下标
不知道该怎么办了。有什么帮助吗?你知道吗
试试这个:
已解决:
必须转换字符串,然后评估那该死的更新对象。你知道吗
当我或我的学生为获得一个深度嵌套的值而挣扎时,我经常通过它来确保我得到了,看到了我所期望的。正如一些评论者所指出的,您的第二个版本可以正常工作,所以在原始代码中一定有一些我们看不到的细微差别。以下是您关心的关键:
相关问题 更多 >
编程相关推荐