# Buggy code
def _start_polling(self, poll_interval, timeout, network_delay, bootstrap_retries):
    """
    Thread target of thread 'updater'. Runs in background, pulls
    updates from Telegram and inserts them in the update queue of the
    Dispatcher.

    """
    cur_interval = poll_interval
    self.logger.debug("Updater thread started")

    self._set_webhook(None, bootstrap_retries, None)

    while self.running:
        try:
            updates = self.bot.getUpdates(
                self.last_update_id, timeout=timeout, network_delay=network_delay
            )
        except TelegramError as te:
            self.logger.error("Error while getting Updates: {0}".format(te))

            # Put the error into the update queue and let the Dispatcher
            # broadcast it
            self.update_queue.put(te)

            cur_interval = self._increase_poll_interval(cur_interval)
        else:
            if not self.running:
                if len(updates) > 0:
                    self.logger.debug(
                        "Updates ignored and will be pulled again on restart."
                    )
                break

            if updates:
                for update in updates:
                    self.update_queue.put(update)
                self.last_update_id = updates[-1].update_id + 1

            cur_interval = poll_interval

        sleep(cur_interval)


# Traceback (telegram.error.NetworkError)
Traceback (most recent call last):
File "main.py", line 43, in <module>
main()
File "main.py", line 34, in main
updates = bot.getUpdates()
File "/usr/local/lib/python3.5/site-packages/telegram/bot.py", line 114, in decorator
result = func(self, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/telegram/bot.py", line 1315, in getUpdates
result = request.post(url, data, timeout=urlopen_timeout)
File "/usr/local/lib/python3.5/site-packages/telegram/utils/request.py", line 83, in decorator
raise NetworkError('URLError: {0}'.format(error.reason))
telegram.error.NetworkError: URLError: _ssl.c:629: The handshake operation timed out

# Fixed code
def _start_polling(
    self, poll_interval, timeout, network_delay, bootstrap_retries, clean
):
    """
    Thread target of thread 'updater'. Runs in background, pulls
    updates from Telegram and inserts them in the update queue of the
    Dispatcher.

    """
    cur_interval = poll_interval
    self.logger.debug("Updater thread started")

    self._bootstrap(bootstrap_retries, clean=clean, webhook_url="")

    while self.running:
        try:
            updates = self.bot.getUpdates(
                self.last_update_id, timeout=timeout, network_delay=network_delay
            )
        except TelegramError as te:
            self.logger.error("Error while getting Updates: {0}".format(te))

            # Put the error into the update queue and let the Dispatcher
            # broadcast it
            self.update_queue.put(te)

            cur_interval = self._increase_poll_interval(cur_interval)
        else:
            if not self.running:
                if len(updates) > 0:
                    self.logger.debug(
                        "Updates ignored and will be pulled again on restart."
                    )
                break

            if updates:
                for update in updates:
                    self.update_queue.put(update)
                self.last_update_id = updates[-1].update_id + 1

            cur_interval = poll_interval

        sleep(cur_interval)