Skip to content

[BUG]How can I make the bot ignore the invalid UTF-8 response? #1609

@rikonaka

Description

@rikonaka

Steps to reproduce

  1. I think it is a small probability event, so I don't know how to reproduce it.

Expected behaviour

Run perfectly.

Actual behaviour

Bot raise error.

2019-11-15 12:50:38,048 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
2019-11-15 12:50:38,048 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8
2019-11-15 12:50:39,220 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
2019-11-15 12:50:39,221 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8

Those error message has been constantly appearing and repeating, causing the program to not work properly.

And I change the logging module form INFO to DEBUG, the more error details show like this.

2019-11-15 11:02:44,710 - telegram.ext.dispatcher - DEBUG - Setting singleton dispatcher as <telegram.ext.dispatcher.Dispatcher object at 0x7ff7b973f358>
2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_submission with t=1573815764.714072
2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_submission_list_clear with t=1573815764.714721
2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_table_name with t=1573815764.714840
2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_table_name_ugly with t=1573815764.714952
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_database_process with t=1573815764.715042
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_repeat_list_delete_one with t=1573815764.715124
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_appreciate_list_delete_one with t=1573815764.715253
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_rest_list_delete_one with t=1573815764.715346
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_sort_by_date_list_delete_one with t=1573815764.715449
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_pic_pool_complete with t=1573815764.715537
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_pic_pool_check with t=1573815764.715622
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_complete with t=1573815764.715753
2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_check with t=1573815764.715847
2019-11-15 11:02:44,716 - JobQueue - DEBUG - Ticking jobs with t=1573815764.716447
2019-11-15 11:02:44,716 - JobQueue - DEBUG - JobQueue thread started
2019-11-15 11:02:44,716 - JobQueue - DEBUG - Peeked at repeat_submission with t=1573815764.714072
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_submission
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_submission with t=1573815770.714072
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_submission_list_clear with t=1573815764.714721
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_submission_list_clear
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_submission_list_clear with t=1573816124.714721
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_table_name with t=1573815764.714840
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_table_name
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_table_name with t=1573815770.714840
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_table_name_ugly with t=1573815764.714952
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_table_name_ugly
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_table_name_ugly with t=1573815770.714952
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_database_process with t=1573815764.715042
2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_database_process
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_database_process with t=1573815767.715042
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_repeat_list_delete_one with t=1573815764.715124
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_repeat_list_delete_one
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_repeat_list_delete_one with t=1573816364.715124
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_appreciate_list_delete_one with t=1573815764.715253
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_appreciate_list_delete_one
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_appreciate_list_delete_one with t=1573815824.715253
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_rest_list_delete_one with t=1573815764.715346
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_rest_list_delete_one
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_rest_list_delete_one with t=1573815824.715346
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_sort_by_date_list_delete_one with t=1573815764.715449
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_sort_by_date_list_delete_one
2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_sort_by_date_list_delete_one with t=1573816364.715449
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_complete with t=1573815764.715537
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_pic_pool_complete
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_pic_pool_complete with t=1573815824.715537
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_check with t=1573815764.715622
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_pic_pool_check
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_pic_pool_check with t=1573815765.715622
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_non_pic_pool_complete with t=1573815764.715753
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_non_pic_pool_complete
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_complete with t=1573815824.715753
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_non_pic_pool_check with t=1573815764.715847
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_non_pic_pool_check
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_check with t=1573815765.715847
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_check with t=1573815765.715622
2019-11-15 11:02:44,719 - JobQueue - DEBUG - Next task isn't due yet. Finished!
2019-11-15 11:02:44,720 - telegram.ext.updater - DEBUG - dispatcher - started
2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - updater - started
2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - Updater thread started (polling)
2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - Start network loop retry bootstrap del webhook
2019-11-15 11:02:44,724 - telegram.bot - DEBUG - Entering: delete_webhook
2019-11-15 11:02:44,724 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): api.telegram.org
2019-11-15 11:02:44,787 - telegram.ext.dispatcher - DEBUG - Dispatcher started
2019-11-15 11:02:45,435 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - https://api.telegram.org:443 "POST /bot627323681:AAHBB-8QBgyu7wPhR_GHIrbbH40YjT5kB2I/deleteWebhook HTTP/1.1" 200 68
2019-11-15 11:02:45,435 - telegram.bot - DEBUG - True
2019-11-15 11:02:45,435 - telegram.bot - DEBUG - Exiting: delete_webhook
2019-11-15 11:02:45,435 - telegram.ext.updater - DEBUG - Bootstrap done
2019-11-15 11:02:45,435 - telegram.ext.updater - DEBUG - Start network loop retry getting Updates
2019-11-15 11:02:45,436 - telegram.bot - DEBUG - Entering: get_updates
2019-11-15 11:02:45,593 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - https://api.telegram.org:443 "POST /bot627323681:AAHBB-8QBgyu7wPhR_GHIrbbH40YjT5kB2I/getUpdates HTTP/1.1" 200 5909
2019-11-15 11:02:45,593 - telegram.utils.request - DEBUG - Logging raw invalid UTF-8 response:
b'{"ok":true,"result":[{"update_id":XXXXXXXXX,\n"message":{"message_id":79819,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","last_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573803803,"reply_to_message":{"message_id":79818,"from":{"id":XXXXXXXXX,"is_bot":true,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573803744,"photo":[{"file_id":"XXXXXXXXX","file_size":3620,"width":200,"height":70}],"caption":"XXXXXXXXX","caption_entities":[{"offset":3,"length":4,"type":"text_mention","user":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","last_name":"XXXXXXXXX","username":"XXXXXXXXX"}}],"reply_markup":{"inline_keyboard":[[{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"}],[{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"},{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"}]]}},"text":"XXXXXXXXX"}},{"update_id":XXXXXXXXX,\n"message":{"message_id":1807,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573804787,"new_chat_participant":{"id":XXXXXXXXX,"is_bot":false,"first_name":" XXXXXXXXX"},"new_chat_member":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"},"new_chat_members":[{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129646,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","language_code":"zh-hans"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573805383,"text":"XXXXXXXXX","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129647,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","language_code":"zh-hans"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573805420,"text":"XXXXXXXXX","entities":[{"offset":0,"length":2,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129648,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810865,"text":"XXXXXXXXX","entities":[{"offset":0,"length":24,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129649,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810886,"text":"XXXXXXXXX","entities":[{"offset":0,"length":24,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129650,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810890,"text":"XXXXXXXXX","entities":[{"offset":0,"length":17,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":109851,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":XXXXXXXXX,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811048,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":XXXXXXXXX,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":366039180,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811339,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":XXXXXXXXX,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":XXXXXXXXX,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811393,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129651,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573813538,"new_chat_participant":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"new_chat_member":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"new_chat_members":[{"id":XXXXXXXXX,is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"}]}}]}'
2019-11-15 11:02:45,593 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
2019-11-15 11:02:45,593 - telegram.ext.dispatcher - DEBUG - Processing Update: Server response could not be decoded using UTF-8
2019-11-15 11:02:45,594 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8

I have replaced some sensitive information with xxxxx.

Configuration

Operating System:
Linux Debian10-1 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux

Version of Python, python-telegram-bot & dependencies:

$ python -m telegram

Output.

>>> python3 -m telegram
python-telegram-bot 11.1.0
certifi 2018.08.24
future 0.17.1
Python 3.7.3 (default, Apr  3 2019, 05:39:12)  [GCC 8.3.0]

So how to make the program ignore this unresolvable data without affecting other processing?

THX.

Logs

Insert logs here (if necessary)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions