{'forward_from_chat': None, 'migrate_to_chat_id': None, 'invoice': None, 'text': u'1', 'sticker': None, 'from_user': {'username': u'bamboo_lee', 'first_name': u'bamboo', 'last_name': u'lee', 'is_bot': False, 'language_code': u'en', 'id': 471214291}, 'caption_entities': None, 'delete_chat_photo': None, 'migrate_from_chat_id': None, 'new_chat_members': None, 'video': None, 'left_chat_member': None, 'chat': {'username': None, 'first_name': None, 'last_name': None, 'description': None, 'title': u'123', 'photo': None, 'pinned_message': None, 'sticker_set_name': None, 'all_members_are_administrators': True, 'invite_link': None, 'type': u'group', 'id': -264835065, 'can_set_sticker_set': None}, 'group_chat_created': None, 'new_chat_photo': None, 'forward_date': None, 'entities': None, 'location': None, 'photo': None, 'author_signature': None, 'document': None, 'forward_from': None, 'supergroup_chat_created': None, 'edit_date': None, 'pinned_message': None, 'content_type': 'text', 'successful_payment': None, 'date': 1514370687, 'new_chat_member': None, 'voice': None, 'reply_to_message': None, 'venue': None, 'message_id': 159, 'caption': None, 'contact': None, 'channel_chat_created': None, 'video_note': None, 'audio': None, 'new_chat_title': None}
這不是json嗎?為什么解析錯誤
<type 'instance'>
2017-12-27 10:31:27,428 (util.py:64 WorkerThread1) ERROR - TeleBot: "TypeError occurred, args=('expected string or buffer',)
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/telebot/util.py", line 58, in run
task(*args, **kwargs)
File "/tmp/pycharm_project_812/main.py", line 19, in handle_messages
data = json.loads(message)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
"
Traceback (most recent call last):
File "/tmp/pycharm_project_812/main.py", line 30, in <module>
bot.polling()
File "/usr/lib/python2.7/site-packages/telebot/__init__.py", line 264, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "/usr/lib/python2.7/site-packages/telebot/__init__.py", line 288, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/usr/lib/python2.7/site-packages/telebot/util.py", line 107, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "/usr/lib/python2.7/site-packages/telebot/util.py", line 58, in run
task(*args, **kwargs)
File "/tmp/pycharm_project_812/main.py", line 19, in handle_messages
data = json.loads(message)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
似乎無需用json再次解析, 直接將數(shù)據(jù)賦予一個字典變量, 即可使用.
data={'forward_from_chat': None, 'migrate_to_chat_id': None, 'invoice': None, 'text': u'1', 'sticker': None, 'from_user': {'username': u'bamboo_lee', 'first_name': u'bamboo', 'last_name': u'lee', 'is_bot': False, 'language_code': u'en', 'id': 471214291}, 'caption_entities': None, 'delete_chat_photo': None, 'migrate_from_chat_id': None, 'new_chat_members': None, 'video': None, 'left_chat_member': None, 'chat': {'username': None, 'first_name': None, 'last_name': None, 'description': None, 'title': u'123', 'photo': None, 'pinned_message': None, 'sticker_set_name': None, 'all_members_are_administrators': True, 'invite_link': None, 'type': u'group', 'id': -264835065, 'can_set_sticker_set': None}, 'group_chat_created': None, 'new_chat_photo': None, 'forward_date': None, 'entities': None, 'location': None, 'photo': None, 'author_signature': None, 'document': None, 'forward_from': None, 'supergroup_chat_created': None, 'edit_date': None, 'pinned_message': None, 'content_type': 'text', 'successful_payment': None, 'date': 1514370687, 'new_chat_member': None, 'voice': None, 'reply_to_message': None, 'venue': None, 'message_id': 159, 'caption': None, 'contact': None, 'channel_chat_created': None, 'video_note': None, 'audio': None, 'new_chat_title': None}
print data['from_user']['is_bot']
output
False
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。