title: python-telegram-bot http.client.RemoteDisconnected: Remote end closed connection without response after executed postponed job_queue.run_once job
body: <p>I wrote a python-telegram-bot in order to get rid of timers and clocks without records of launch.
  But unfortunately on testing I ran into strange problem I couldn't understand - a HTTPError (<code>http.client.RemoteDisconnected: Remote end closed connection without response</code>) happens every time when a job in job_queue is executing after selected 15-minute delay.<br />
  I tried to google this problem and added some keyword arguments <code>timeout=3600</code> in the code but this change has no influence on bot's perfomance.
  Could anyone clarify what things I don't understand?
  Much obliged in advance.</p>
  <p>here is my code consisting of two files:</p>
  <p><code>test_bot.py</code></p>
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  import logging
  import pytz
  import telegram_bot_config as t
  
  from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
  from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler, Defaults
  import datetime as dt
  
  # Enable logging
  logging.basicConfig(
      format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
  )
  
  logger = logging.getLogger(__name__)
  
  def make_kb():
      keyboard = [
          [InlineKeyboardButton(&quot;Send message in 15 minutes&quot;, callback_data=t.BUTTON_LABEL1)],
          [InlineKeyboardButton(&quot;Send message in 4 hours&quot;, callback_data=t.BUTTON_LABEL2)],
      ]
  
      reply_markup = InlineKeyboardMarkup(keyboard)
      return reply_markup
  
  
  def start(update: Update, context: CallbackContext) -&gt; None:
      &quot;&quot;&quot;Sends a message with three inline buttons attached.&quot;&quot;&quot;
      reply_markup = make_kb()
      update.message.reply_text('Please choose:', reply_markup=reply_markup)
  
  
  def alarm(context: CallbackContext) -&gt; None:
      &quot;&quot;&quot;Send the alarm message.&quot;&quot;&quot;
      job = context.job
      dt_now = dt.datetime.now()
      dt_now_str = dt.datetime.strftime(dt_now, '%Y-%m-%d %H:%M:%S')
  
      delta_dt = (dt_now - dt.datetime.strptime(job.context[&quot;dt_start&quot;], '%Y-%m-%d %H:%M:%S'))
      elapsed = dt.timedelta(delta_dt.total_seconds())
      answer = '{0} were elapsed!*'.format(elapsed)
      text_message = &quot;You had pressed the button at *{0}*.\nAfter waiting I sent it at *{1}*&quot;.format(
          job.context[&quot;dt_start&quot;],
          dt_now_str)
      context.bot.send_message(job.context[&quot;chat_id&quot;], text=answer, parse_mode=ParseMode.MARKDOWN)
      context.bot.send_message(job.context[&quot;chat_id&quot;], text=text_message, parse_mode=ParseMode.MARKDOWN)
  
  
  def button(update: Update, context: CallbackContext) -&gt; None:
      &quot;&quot;&quot;Parses the CallbackQuery and updates the message text.&quot;&quot;&quot;
      query = update.callback_query
      query.answer()
      data = query.data
      query.message.reply_text(&quot;You selected *&quot; + data + &quot;* option!&quot;, parse_mode=ParseMode.MARKDOWN)
  
      dt_start = dt.datetime.now()
      chat_id = query.message.chat_id
      payload = {&quot;chat_id&quot;: chat_id, &quot;dt_start&quot;: dt.datetime.strftime(dt_start, '%Y-%m-%d %H:%M:%S')}
  
      if data == '15m':
          context.job_queue.run_once(alarm, t.DURATION_15M, context=payload, name=str(chat_id))
      if data == '4h':
          context.job_queue.run_once(alarm, t.DURATION_4H, context=payload, name=str(chat_id))
  
  
  if __name__ == '__main__':
      &quot;&quot;&quot;Run bot.&quot;&quot;&quot;
      defaults = Defaults(parse_mode=ParseMode.HTML, tzinfo=pytz.timezone('Europe/Moscow'),)
  
      updater = Updater(t.TOKEN, request_kwargs={'read_timeout': 4*3600, 'connect_timeout': 4*3600})
  
      updater.dispatcher.add_handler(CommandHandler(&quot;start&quot;, start))
      updater.dispatcher.add_handler(CallbackQueryHandler(button))
  
      # Start the Bot
      updater.start_polling(timeout=4*3600)
  
      updater.idle()
  </code></pre>
  <p><code>telegram_bot_config.py</code></p>
  <pre><code># -*- coding: utf-8 -*-
  TOKEN = &quot;YOUR TOKEN HERE!&quot;
  
  DURATION_15M = 60*15
  DURATION_4H = 60*60*4
  
  BUTTON_LABEL1 = &quot;15m&quot;
  BUTTON_LABEL2 = &quot;4h&quot;
  </code></pre>
  <p>An error which occurs every time after 15-minute waiting of message:</p>
  <pre><code>C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\Scripts\python.exe C:/Users/test/Dropbox/Development/TelegramTimerBot/test4.py
  2021-07-01 22:43:37,315 - apscheduler.scheduler - INFO - Scheduler started
  2021-07-01 22:43:43,133 - apscheduler.scheduler - INFO - Added job &quot;1234567&quot; to job store &quot;default&quot;
  2021-07-01 22:58:43,098 - apscheduler.executors.default - INFO - Running job &quot;1234567 (trigger: date[2021-07-01 19:58:43 UTC], next run at: 2021-07-01 19:58:43 UTC)&quot; (scheduled at 2021-07-01 19:58:43.092836+00:00)
  2021-07-01 22:58:43,099 - apscheduler.scheduler - INFO - Removed job 8ed316fd7340464b948d0f41bce318de
  2021-07-01 22:58:43,105 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
  Traceback (most recent call last):
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 617, in urlopen
      chunked=chunked)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 402, in _make_request
      six.raise_from(e, None)
    File &quot;&lt;string&gt;&quot;, line 2, in raise_from
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 398, in _make_request
      httplib_response = conn.getresponse()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 1344, in getresponse
      response.begin()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 306, in begin
      version, status, reason = self._read_status()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 275, in _read_status
      raise RemoteDisconnected(&quot;Remote end closed connection without&quot;
  http.client.RemoteDisconnected: Remote end closed connection without response
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\utils\request.py&quot;, line 259, in _request_wrapper
      resp = self._con_pool.request(*args, **kwargs)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\request.py&quot;, line 70, in request
      **urlopen_kw)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\request.py&quot;, line 148, in request_encode_body
      return self.urlopen(method, url, **extra_kw)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\poolmanager.py&quot;, line 244, in urlopen
      response = conn.urlopen(method, u.request_uri, **kw)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 666, in urlopen
      _stacktrace=sys.exc_info()[2])
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\util\retry.py&quot;, line 347, in increment
      raise six.reraise(type(error), error, _stacktrace)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\packages\six.py&quot;, line 685, in reraise
      raise value.with_traceback(tb)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 617, in urlopen
      chunked=chunked)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 402, in _make_request
      six.raise_from(e, None)
    File &quot;&lt;string&gt;&quot;, line 2, in raise_from
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py&quot;, line 398, in _make_request
      httplib_response = conn.getresponse()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 1344, in getresponse
      response.begin()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 306, in begin
      version, status, reason = self._read_status()
    File &quot;C:\Python37\lib\http\client.py&quot;, line 275, in _read_status
      raise RemoteDisconnected(&quot;Remote end closed connection without&quot;
  telegram.vendor.ptb_urllib3.urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\apscheduler\executors\base.py&quot;, line 125, in run_job
      retval = job.func(*job.args, **job.kwargs)
    File &quot;C:/Users/test/Dropbox/Development/TelegramTimerBot/test4.py&quot;, line 52, in alarm
      context.bot.send_message(job.context[&quot;chat_id&quot;], text=text_message, parse_mode=ParseMode.MARKDOWN)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\bot.py&quot;, line 129, in decorator
      result = func(*args, **kwargs)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\bot.py&quot;, line 507, in send_message
      api_kwargs=api_kwargs,
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\ext\extbot.py&quot;, line 206, in _message
      api_kwargs=api_kwargs,
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\bot.py&quot;, line 331, in _message
      result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs)
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\bot.py&quot;, line 295, in _post
      f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\utils\request.py&quot;, line 361, in post
      **urlopen_kwargs,
    File &quot;C:\Users\test\Dropbox\Development\TelegramTimerBot\venv\lib\site-packages\telegram\utils\request.py&quot;, line 265, in _request_wrapper
      raise NetworkError(f'urllib3 HTTPError {error}') from error
  telegram.error.NetworkError: urllib3 HTTPError ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
  </code></pre>