当前位置: 首页>>代码示例>>Python>>正文


Python error.TimedOut方法代码示例

本文整理汇总了Python中telegram.error.TimedOut方法的典型用法代码示例。如果您正苦于以下问题:Python error.TimedOut方法的具体用法?Python error.TimedOut怎么用?Python error.TimedOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telegram.error的用法示例。


在下文中一共展示了error.TimedOut方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: notify

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def notify(bot, job):
    """
    Send notification to user
    
    Args:
        :param bot: <telegram.Bot> bot instance
        :param job: <telegram.ext.jobqueue.Job> user's job instance
         
    """
    res = crawl(job.context['chat_id'])
    if len(res) > 0:
        try:
            bot.send_message(chat_id=job.context['chat_id'], text=_generate_string(res), parse_mode=messages.MARKDOWN)
        except Unauthorized:
            job.schedule_removal()
            mq.update_setting(job.context['chat_id'], setting=base_config.NOTIFICATIONS, value=False)
        except TimedOut:
            logger.warning('chat_id: {}; error: {}'.format(job.context['chat_id'],
                                                           'Time out while sending notification'))
        except Exception as e:
            logger.warning('chat_id: {}; error: {}\n'
                           '{}'.format(job.context['chat_id'], str(e), format_exc())) 
开发者ID:Cindicator,项目名称:CindicatorArbitrageBot,代码行数:24,代码来源:core.py

示例2: test_handle_callback_with_timeout_sends_message

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def test_handle_callback_with_timeout_sends_message(mocker, sample_movie, caplog):
    bot, update = mocker.MagicMock(), mocker.MagicMock()
    update.callback_query.data = NEXT_YTS
    mocker.patch('commands.yts.utils.InputMediaPhoto', side_effect=TimedOut)
    chat_data = {
        'context': {
            'data': [sample_movie, sample_movie],
            'movie_number': 0,
            'movie_count': 1,
            'command': 'yts',
            'edit_original_text': True,
        }
    }
    caplog.set_level(logging.INFO)
    handle_callback(bot, update, chat_data)
    assert bot.send_message.call_count == 1
    assert (
            bot.send_message.call_args[1]['text']
            == 'Request for new photo timed out. Try again.'
    )
    assert "Could not build InputMediaPhoto from url" in caplog.text 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:23,代码来源:test_handle_callback.py

示例3: failwithmessage

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def failwithmessage(func):
    @wraps(func)
    def wrapped(update: Update, context: CallbackContext, *args, **kwargs):
        try:
            return func(update, context, *args, **kwargs)
        except TimedOut:
            logger.error('TimedOut error')
            # memo: timed out errors break conversation handlers because the new state isn't returned
        except Exception as e:
            logger.error('unexpected error while running handler callback: %s', str(e), exc_info=True)
            text = 'An error occurred while processing the message: <code>{}</code>'.format(html_escape(str(e)))
            if update.callback_query:
                update.callback_query.message.reply_html(text)
            else:
                update.message.reply_html(text)

    return wrapped 
开发者ID:zeroone2numeral2,项目名称:tnt-village-bot,代码行数:19,代码来源:decorators.py

示例4: push_simple

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def push_simple(bot, chat_id, message):
	try:
		bot.sendMessage(chat_id=chat_id, text=message)
	except BadRequest as e:
		bot.sendMessage(chat_id=chat_id, text=replace_unsafe(message))
	except RetryAfter as e:
		sleep(240)
		bot.sendMessage(chat_id=chat_id, text=message)
	except TimedOut as e:
		sleep(60)
		bot.sendMessage(chat_id=chat_id, text=message)
	except Unauthorized as e:
		sleep(0.25)
	except NetworkError as e:
		sleep(30)
		bot.sendMessage(chat_id=chat_id, text=message)
	except Exception as e:
		sleep(1)
		bot.sendMessage(chat_id=chat_id, text=message) 
开发者ID:SergiySW,项目名称:NanoWalletBot,代码行数:21,代码来源:common.py

示例5: download_file

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def download_file(file_id):
    try:
        # download file
        file = bot.get_file(file_id=file_id, timeout=30)
        ext = '.' + file.file_path.split('/')[-1].split('.')[1]
        download_path = os.path.join(temp_dir(), (file_id + ext))
        file.download(custom_path=download_path)

        return download_path
    except TimedOut:
        raise TimedOut


#  _____                          _       _   _                       _   _
# | ____| __   __   ___   _ __   | |_    | | | |   __ _   _ __     __| | | |   ___   _ __   ___
# |  _|   \ \ / /  / _ \ | '_ \  | __|   | |_| |  / _` | | '_ \   / _` | | |  / _ \ | '__| / __|
# | |___   \ V /  |  __/ | | | | | |_    |  _  | | (_| | | | | | | (_| | | | |  __/ | |    \__ \
# |_____|   \_/    \___| |_| |_|  \__|   |_| |_|  \__,_| |_| |_|  \__,_| |_|  \___| |_|    |___/ 
开发者ID:fxuls,项目名称:ez-sticker-bot,代码行数:20,代码来源:ezstickerbot.py

示例6: get_invalid_channel_access

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def get_invalid_channel_access(bot):
    configs = helper_database.get_all_channel_config()
    invalid_list = []
    for config in configs:
        channel_id = int(config[0])
        admin_id = int(config[5])
        try:
            chat_members = bot.get_chat_administrators(chat_id=channel_id).result()
        except TimedOut:
            pass
        except NetworkError:
            pass
        except:
            invalid_list.append(config)
    return invalid_list 
开发者ID:JogleLew,项目名称:channel-helper-bot,代码行数:17,代码来源:clean_cmd.py

示例7: error_callback

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def error_callback(bot, update, error):
    try:
        raise error
    except Unauthorized:
        print("no nono1")
        print(error)
        # remove update.message.chat_id from conversation list
    except BadRequest:
        print("no nono2")
        print("BadRequest caught")
        print(error)

        # handle malformed requests - read more below!
    except TimedOut:
        print("no nono3")
        # handle slow connection problems
    except NetworkError:
        print("no nono4")
        # handle other connection problems
    except ChatMigrated as err:
        print("no nono5")
        print(err)
        # the chat_id of a group has changed, use e.new_chat_id instead
    except TelegramError:
        print(error)
        # handle all other telegram related errors 
开发者ID:skittles9823,项目名称:SkittBot,代码行数:28,代码来源:__main__.py

示例8: get_photo

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def get_photo(image_url):
    """Build InputMediaPhoto from image url"""
    try:
        return InputMediaPhoto(image_url)
    except TimedOut:
        logger.info('Request for photo from %s timed out.', image_url)
        logger.info('Retrying..')
        try:
            return InputMediaPhoto(image_url)
        except TimedOut:
            logger.info('Retry Failed.')
            return None 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:14,代码来源:utils.py

示例9: test_get_photo_retry_works

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def test_get_photo_retry_works(mocker, caplog):
    caplog.set_level(logging.INFO)
    mocker.patch(
        'commands.yts.utils.InputMediaPhoto', side_effect=[TimedOut, 'photo_url']
    )
    assert get_photo('url_img') == 'photo_url'
    assert 'Retrying..' in caplog.text 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:9,代码来源:test_handle_callback.py

示例10: test_get_photo_returns_none_on_timeout

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def test_get_photo_returns_none_on_timeout(mocker, caplog):
    caplog.set_level(logging.INFO)
    mocker.patch('commands.yts.utils.InputMediaPhoto', side_effect=TimedOut)
    assert get_photo('url_img') is None
    assert 'Retry Failed.' in caplog.text 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:7,代码来源:test_handle_callback.py

示例11: extract_text

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def extract_text(tg_sticker):
    """Extract the text from a telegram sticker."""
    text = None
    logger = logging.getLogger()
    try:
        # Get Image and preprocess it
        tg_file = call_tg_func(tg_sticker, "get_file")
        image_bytes = call_tg_func(tg_file, "download_as_bytearray")
        with Image.open(io.BytesIO(image_bytes)).convert("RGB") as image:
            image = preprocess_image(image)

            # Extract text
            text = image_to_string(image).strip().lower()

        # Only allow chars and remove multiple spaces to single spaces
        text = re.sub("[^a-zA-Z\ ]+", "", text)
        text = re.sub(" +", " ", text)
        text = text.strip()
        if text == "":
            text = None

    except TimedOut:
        logger.info(f"Finally failed on file {tg_sticker.file_id}")
        pass
    except BadRequest:
        logger.info(f"Failed to get image of {tg_sticker.file_id}")
        pass
    except OSError:
        logger.info(f"Failed to open image {tg_sticker.file_id}")
        pass
    except:
        sentry.captureException()
        pass

    return text 
开发者ID:Nukesor,项目名称:sticker-finder,代码行数:37,代码来源:sticker_set.py

示例12: custom_keyboard

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def custom_keyboard(bot, chat_id, buttons, text):
	reply_markup = ReplyKeyboardMarkup(buttons, resize_keyboard = True)
	try:
		bot.sendMessage(chat_id=chat_id, 
					 text=text, 
					 parse_mode=ParseMode.MARKDOWN,
					 disable_web_page_preview=True,
					 reply_markup=reply_markup)
	except BadRequest:
		bot.sendMessage(chat_id=chat_id, 
					 text=replace_unsafe(text), 
					 parse_mode=ParseMode.MARKDOWN,
					 disable_web_page_preview=True,
					 reply_markup=reply_markup)
	except RetryAfter:
		sleep(240)
		bot.sendMessage(chat_id=chat_id, 
					 text=text, 
					 parse_mode=ParseMode.MARKDOWN,
					 disable_web_page_preview=True,
					 reply_markup=reply_markup)
	except TimedOut:
		sleep(10)
		bot.sendMessage(chat_id=chat_id, 
					 text=text, 
					 parse_mode=ParseMode.MARKDOWN,
					 disable_web_page_preview=True,
					 reply_markup=reply_markup)
	except:
		sleep(1)
		bot.sendMessage(chat_id=chat_id, 
					 text=text, 
					 parse_mode=ParseMode.MARKDOWN,
					 disable_web_page_preview=True,
					 reply_markup=reply_markup) 
开发者ID:SergiySW,项目名称:NanoWalletBot,代码行数:37,代码来源:raiwalletbot.py

示例13: message_markdown

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def message_markdown(bot, chat_id, message):
	try:
		bot.sendMessage(chat_id=chat_id, 
					text=message,
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True)
	except BadRequest:
		bot.sendMessage(chat_id=chat_id, 
					text=replace_unsafe(message),
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True)
	except RetryAfter:
		sleep(240)
		bot.sendMessage(chat_id=chat_id, 
					text=message,
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True)
	except TimedOut as e:
		sleep(60)
		bot.sendMessage(chat_id=chat_id, 
					text=message,
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True)
	except Unauthorized as e:
		sleep(0.25)
	except NetworkError as e:
		sleep(30)
		bot.sendMessage(chat_id=chat_id, 
					text=message,
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True)
	except Exception as e:
		sleep(1)
		bot.sendMessage(chat_id=chat_id, 
					text=message,
					parse_mode=ParseMode.MARKDOWN,
					disable_web_page_preview=True) 
开发者ID:SergiySW,项目名称:NanoWalletBot,代码行数:39,代码来源:common.py

示例14: text_reply

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def text_reply(update, text):
	try:
		update.message.reply_text(text)
	except TimedOut as e:
		sleep(60)
		update.message.reply_text(text)
	except NetworkError as e:
		sleep(30)
		update.message.reply_text(text)
	except Exception as e:
		sleep(1)
		update.message.reply_text(text) 
开发者ID:SergiySW,项目名称:NanoWalletBot,代码行数:14,代码来源:common.py

示例15: ignore_job_exception

# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TimedOut [as 别名]
def ignore_job_exception(exception):
    """Check whether we can safely ignore this exception."""
    if isinstance(exception, TimedOut):
        return True

    return False 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:8,代码来源:session.py


注:本文中的telegram.error.TimedOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。