telegram.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:telegram-bot-framework 作者: alvarogzp 项目源码 文件源码
def __create_session(self):
        session = requests.session()
        # Retry one time on read errors, as the connection could have been closed
        # by the remote side and its close notification might have been lost,
        # blocked by firewall or dropped by NAT.
        # In that case, the session will try to reuse the connection thinking it is
        # still alive just to fail with a read error when the remote sends the reset.
        #
        # So, by retrying in that case we avoid this error and do not lose that api
        # call, which could be translated in a message lost.
        # That way we try to get the same behavior as we had when not using sessions.
        #
        # The drawback is that we could also be masquerading some *real* read errors
        # and retrying a request already processed by the server, repeating some
        # action (eg. a duplicate message).
        # But, during a year of production use we never had any read error of this kind.
        #
        # Update:
        # Due to a duplicate message case during a telegram bot api partial failure,
        # we are disabling the retry policy.
        # That way, if the edge described above happens a message won't be sent but
        # we will get an error. With the retry policy, a duplicate message could be
        # sent silently on poor network conditions.
        # So, it is preferable a message lost with the error being logged than a
        # duplicate message without noticing it.

        # retry = Retry(total=1, connect=0, read=1, status=0, respect_retry_after_header=False)
        # passing prefix lowered to work-around https://github.com/requests/requests/pull/4349
        # session.mount(self.base_url.lower(), HTTPAdapter(max_retries=retry))
        return session
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号