title: Failing to deploy a aiogram python bot in webhook mode
body: <p>I have tried this script which is similar to <a href="https://github.com/aiogram/aiogram/blob/dev-2.x/examples/webhook_example.py" rel="nofollow noreferrer">aiogram official example</a> for webhook deployment.</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import logging
  
  from aiogram import Bot, Dispatcher, types, executor
  
  PROJECT_NAME = os.environ.get(&quot;PROJ&quot;)
  TOKEN = os.environ.get(&quot;TOKEN&quot;)
  
  WEBHOOK_HOST = f&quot;https://{PROJECT_NAME}.herokuapp.com&quot;
  WEBHOOK_PATH = &quot;/webhook/&quot; + TOKEN
  WEBHOOK_URL = f&quot;{WEBHOOK_HOST}{WEBHOOK_PATH}&quot;
  
  WEBAPP_HOST = &quot;localhost&quot;
  WEBAPP_PORT = 8443
  
  bot = Bot(TOKEN)
  dp = Dispatcher(bot)
  
  logging.basicConfig(level=logging.INFO)
  
  
  # Example handler
  @dp.message_handler(commands=&quot;start&quot;)
  async def start_handler(message: types.Message):
      await bot.send_message(message.chat.id, text=&quot;hi&quot;)
  
  
  # Run after startup
  async def on_startup():
      await bot.delete_webhook()
      await bot.set_webhook(WEBHOOK_URL)
  
  
  # Run before shutdown
  async def on_shutdown():
      logging.warning(&quot;Shutting down..&quot;)
      await bot.delete_webhook()
      await dp.storage.close()
      await dp.storage.wait_closed()
      logging.warning(&quot;Bot down&quot;)
  
  
  if __name__ == &quot;__main__&quot;:
      if &quot;HEROKU&quot; in list(os.environ.keys()):
          executor.start_webhook(
              dispatcher=dp,
              webhook_path=WEBHOOK_PATH,
              on_startup=on_startup,
              on_shutdown=on_shutdown,
              skip_updates=True,
              host=WEBAPP_HOST,
              port=WEBAPP_PORT,
          )
      else:
          executor.start_polling(dp)
  </code></pre>
  <p>Polling worked fine for a few seconds and then crashed.</p>
  <p>I have set the environment variables as follows:</p>
  <p><code>TOKEN</code> ( token from BotFather )
  , <code>PROJ</code> ( name of Heroku project )</p>
  <p>AND <code>HEROKU</code> ( valueless )</p>
  <p>After deploying,</p>
  <pre><code>2020-11-21T16:06:33.939710+00:00 heroku[web.1]: State changed from crashed to starting
  2020-11-21T16:06:38.339135+00:00 heroku[web.1]: Starting process with command `python bot.py`
  2020-11-21T16:06:42.115941+00:00 heroku[web.1]: Process exited with status 1
  2020-11-21T16:06:42.169072+00:00 heroku[web.1]: State changed from starting to crashed
  2020-11-21T16:06:41.819141+00:00 app[web.1]: INFO:aiogram:Bot: AahnikTester [@aahniks_tester_bot]
  2020-11-21T16:06:41.987742+00:00 app[web.1]: WARNING:aiogram:Updates were skipped successfully.
  2020-11-21T16:06:41.990985+00:00 app[web.1]: ERROR:asyncio:unhandled exception during asyncio.run() shutdown
  2020-11-21T16:06:41.990986+00:00 app[web.1]: task: &lt;Task finished name='Task-6' coro=&lt;_run_app() done, defined at /app/.heroku/python/lib/python3.8/site-packages/aiohttp/web.py:287&gt; exception=TypeError('on_startup() takes 0 positional arguments but 1 was given')&gt;
  2020-11-21T16:06:41.990986+00:00 app[web.1]: Traceback (most recent call last):
  2020-11-21T16:06:41.990987+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web.py&quot;, line 508, in run_app
  2020-11-21T16:06:41.990987+00:00 app[web.1]:     loop.run_until_complete(main_task)
  2020-11-21T16:06:41.990988+00:00 app[web.1]:   File &quot;uvloop/loop.pyx&quot;, line 1456, in uvloop.loop.Loop.run_until_complete
  2020-11-21T16:06:41.990988+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web.py&quot;, line 319, in _run_app
  2020-11-21T16:06:41.990989+00:00 app[web.1]:     await runner.setup()
  2020-11-21T16:06:41.990990+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_runner.py&quot;, line 275, in setup
  2020-11-21T16:06:41.990990+00:00 app[web.1]:     self._server = await self._make_server()
  2020-11-21T16:06:41.990990+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_runner.py&quot;, line 375, in _make_server
  2020-11-21T16:06:41.990991+00:00 app[web.1]:     await self._app.startup()
  2020-11-21T16:06:41.990991+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_app.py&quot;, line 416, in startup
  2020-11-21T16:06:41.990992+00:00 app[web.1]:     await self.on_startup.send(self)
  2020-11-21T16:06:41.990992+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/signals.py&quot;, line 34, in send
  2020-11-21T16:06:41.990993+00:00 app[web.1]:     await receiver(*args, **kwargs)  # type: ignore
  2020-11-21T16:06:41.990993+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiogram/utils/executor.py&quot;, line 250, in _wrap_callback
  2020-11-21T16:06:41.990993+00:00 app[web.1]:     return await cb(self.dispatcher)
  2020-11-21T16:06:41.990994+00:00 app[web.1]: TypeError: on_startup() takes 0 positional arguments but 1 was given
  2020-11-21T16:06:41.991678+00:00 app[web.1]: Traceback (most recent call last):
  2020-11-21T16:06:41.991741+00:00 app[web.1]:   File &quot;bot.py&quot;, line 45, in &lt;module&gt;
  2020-11-21T16:06:41.992057+00:00 app[web.1]:     executor.start_webhook(
  2020-11-21T16:06:41.992112+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiogram/utils/executor.py&quot;, line 98, in start_webhook
  2020-11-21T16:06:41.992386+00:00 app[web.1]:     executor.run_app(**kwargs)
  2020-11-21T16:06:41.992389+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiogram/utils/executor.py&quot;, line 282, in run_app
  2020-11-21T16:06:41.992703+00:00 app[web.1]:     web.run_app(self._web_app, **kwargs)
  2020-11-21T16:06:41.992706+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web.py&quot;, line 508, in run_app
  2020-11-21T16:06:41.993089+00:00 app[web.1]:     loop.run_until_complete(main_task)
  2020-11-21T16:06:41.993090+00:00 app[web.1]:   File &quot;uvloop/loop.pyx&quot;, line 1456, in uvloop.loop.Loop.run_until_complete
  2020-11-21T16:06:41.993309+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web.py&quot;, line 319, in _run_app
  2020-11-21T16:06:41.993604+00:00 app[web.1]:     await runner.setup()
  2020-11-21T16:06:41.993607+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_runner.py&quot;, line 275, in setup
  2020-11-21T16:06:41.993862+00:00 app[web.1]:     self._server = await self._make_server()
  2020-11-21T16:06:41.993865+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_runner.py&quot;, line 375, in _make_server
  2020-11-21T16:06:41.994180+00:00 app[web.1]:     await self._app.startup()
  2020-11-21T16:06:41.994186+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/web_app.py&quot;, line 416, in startup
  2020-11-21T16:06:41.994510+00:00 app[web.1]:     await self.on_startup.send(self)
  2020-11-21T16:06:41.994534+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiohttp/signals.py&quot;, line 34, in send
  2020-11-21T16:06:41.994724+00:00 app[web.1]:     await receiver(*args, **kwargs)  # type: ignore
  2020-11-21T16:06:41.994724+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.8/site-packages/aiogram/utils/executor.py&quot;, line 250, in _wrap_callback
  2020-11-21T16:06:41.994977+00:00 app[web.1]:     return await cb(self.dispatcher)
  2020-11-21T16:06:41.995020+00:00 app[web.1]: TypeError: on_startup() takes 0 positional arguments but 1 was given
  
  </code></pre>
  <p>I am looking for an example of aiogram's deployment to heroku using webhook.</p>
  <h3>With some tweaks to above code, this came</h3>
  <pre><code>2020-11-26T09:32:27.283413+00:00 app[web.1]: WARNING:aiogram:Updates were skipped successfully.
  2020-11-26T09:32:27.283425+00:00 app[web.1]: WARNING:root:Starting webhook
  2020-11-26T09:32:27.455462+00:00 app[web.1]: WARNING:root:Webhook set
  2020-11-26T09:32:27.457534+00:00 app[web.1]: ======== Running on http://localhost:8443 ========
  2020-11-26T09:32:27.457535+00:00 app[web.1]: (Press CTRL+C to quit)
  2020-11-26T09:33:23.679946+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web process failed to bind to $PORT within 60 seconds of launch
  </code></pre>
  <p>how to fix this ? ( in heroku )</p>
  <h3>with some other tweaks</h3>
  <p>the webhook is being set correctly because telegram is sending updates. but they are not being handled. thats why another error is coming.</p>
  <pre><code>2020-11-26T09:52:48.395734+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=POST path=&quot;/webhook/secret_key...&quot; host=radiant-caverns-48683.herokuapp.com
  </code></pre>