1

I want to take user data from array["from"], but when i want to print it, it says None

This is for python 2.xx. in the past i've tried with a basic array and it works fine, but when I use an Instagram bot and print in an app it doesn't work fine

print update.message
print update.message['from']

First code output :

> {'delete_chat_photo': False, 'new_chat_photo': [], 'from':
> {'first_name': u'error', 'is_bot': False, 'id': 0000000,
> 'language_code': u'kkk'}, 'text': u'namaewa?', 'caption_entities': [],
> 'entities': [], 'channel_chat_created': False, 'new_chat_members': [],
> 'supergroup_chat_created': False, 'chat': {'type': u'supergroup',
> 'id': -0, 'title': u'IE'}, 'photo': [], 'date': 1565793310,
> 'group_chat_created': False, 'message_id': 159}

Second code output :

> None
bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
Nadif15
  • 11
  • 1
  • 1
    What about `print type(update.message)`? – CristiFati Aug 14 '19 at 14:47
  • For Instagram, if a message is returning `None`, it's most probable that there is no message in the user's inbox. –  Aug 14 '19 at 14:51
  • After your edit, I can see the message is a dict. I'm able to get the correct value from the dict for the key. But I'm using Python 3. You can try `message.get('from') `[ref](https://stackoverflow.com/questions/6130768/return-none-if-dictionary-key-is-not-available). Also, why python2?? https://pythonclock.org/ – Brennan Aug 14 '19 at 14:54
  • 'Message' object has no attribute 'get' @Brennan – Nadif15 Aug 14 '19 at 15:16
  • @CristiFati – Nadif15 Aug 14 '19 at 15:17
  • @Cygnus as you can see the first output the text mean the msg – Nadif15 Aug 14 '19 at 15:19

1 Answers1

0

You are trying to use telegram.message like a dictionary, but it's not. If you want the "from" portion, then you need to use telegram.message.from_user to get a return of type telegram.User

You can read about it in the telegram docs

Brennan
  • 504
  • 3
  • 14