-
Notifications
You must be signed in to change notification settings - Fork 477
KeyError exception in __init__.py line 792 #184
Comments
Yeah When I send message to bot from Channel I receive this error Too: |
@Shayan123456 @nickoala The issue is related to Telegram Channels. Here's a sample message that will make it crash (from https://api.telegram.org/botXXXXXXXXXXX/getUpdates):
My bot was added as a channel admin. So the exception is thrown as the message type is "channel_post" (or also "edit_channel_post") which is not included in https://github.com/nickoala/telepot/blob/master/telepot/__init__.py at line 776 Here's quick and dirty fix: replace relay_to_collector function in init.py at line 774 with this one: def relay_to_collector(update):
key = _find_first_key(update, ['message',
'channel_post',
'edited_channel_post',
'edited_message',
'callback_query',
'inline_query',
'chosen_inline_result'])
collect_queue.put(update[key])
return update['update_id'] This will at least prevent the bot from crashing on startup. |
This seems to be related to the changes in Bot API 2.3. Expect an update on or before Nov 30. |
Can I suggest a better error message?
Maybe even return what is the name of the not expected key. I was coding when the error started to happen and I spent sometime until I undernstood what the problems was. |
I have same error
|
Okay so here's the solution to fix telepot with the new API (2.3): Replace function relay_to_collector in file init.py at line 774 with: def relay_to_collector(update):
key = _find_first_key(update, ['message',
'channel_post',
'edited_channel_post',
'edited_message',
'callback_query',
'inline_query',
'chosen_inline_result'])
collect_queue.put(update[key])
return update['update_id'] Now in your bot's code to find out the chat type you can do: def handle(msg):
type = msg['chat']['type']
if type == "private":
#message from msg['chat']['first_name']
else:
#message from msg['chat']['title'] I'd wait until the next release of telepot to mark this issue as closed. |
@carloalbertobarbano I use something like this
|
@efazati you have to edit the telepot library yourself for now. Just replace the function in this file https://github.com/nickoala/telepot/blob/master/telepot/__init__.py as described above. You can find the correct path for that file on your machine in the traceback of the exception |
@carloalbertobarbano I did change that code, but what about handle in my code? i use with this method and i dont have method like your handle i mean this
|
@efazati That was just a sample. You can use telepot in the way you are used to without further changes. Let's keep this thread for this library bug only and free from other implementation-specific issues. |
For all who dont want to wait update u can fix this problem by theyself, just add at 780 string at init.py (in relay_to_collector(update) this function) to list one value 'channel_post' |
Oh, im sort of slowpoke)) sorry) |
Following this issue, how could I know which channel my bot has been added to? Is there a way? |
@96Octavian, when a bot is added to a group, it receives a On the other hand, I have updated telepot (10.2) to encompass Bot API 2.3. Just do:
This issue should be no more. Thanks everyone for using telepot 😊 |
Same error in the latest bot API update when working with polls.
got a monkey patch like this for the Bot API 4.2 poll update? |
Telepot throws an exception while retrieveing messages from telegram servers. Here's the traceback:
(traceback from OSX)
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/telepot/__init__.py", line 792, in get_from_telegram_server offset = max([relay_to_collector(update) for update in result]) + 1 File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/telepot/__init__.py", line 792, in <listcomp> offset = max([relay_to_collector(update) for update in result]) + 1 File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/telepot/__init__.py", line 779, in relay_to_collector 'chosen_inline_result']) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/telepot/__init__.py", line 61, in _find_first_key raise KeyError(keys) KeyError: ['message', 'edited_message', 'callback_query', 'inline_query', 'chosen_inline_result']
Here's the code:
My bot no longer receives messages
The text was updated successfully, but these errors were encountered: