title: Telethon Python asyncio TypeError: 'coroutine' object is not callable
body: <p>you need to get information about the channel, chat, group.
  Since each account has a restriction on receiving information, I will use several accounts.
  I'm trying to get information, but I get an error:</p>
  
  <pre><code> Traceback (most recent call last):
    File "D:/Git/telegram/telegram_new.py", line 50, in parse_entity
      channel=entity
  TypeError: 'coroutine' object is not callable
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "D:/Git/telegram/telegram_new.py", line 56, in parse_entity
      id=entity
  TypeError: 'coroutine' object is not callable
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "D:/Git/telegram/telegram_new.py", line 60, in parse_entity
      chat_id=entity
  TypeError: 'coroutine' object is not callable
  </code></pre>
  
  <p>Help fix the error</p>
  
  <p>Code:</p>
  
  <pre><code>import logging
  from telethon import TelegramClient,sync, utils, errors
  from telethon.tl.types import PeerUser, PeerChat
  from telethon import functions, types
  import pandas as pd
  import time
  import re
  import asyncio
  from contextlib import suppress
  import traceback
  
  log = logging.getLogger(__name__)
  format = '%(asctime)s %(levelname)s:%(message)s'
  logging.basicConfig(format=format, level=logging.INFO)
  
  api_id = ""              #(my.telegram.org)
  api_hash = ""
  
  filename_excel = "project_for_export_no_formulas_31_10_18.xlsx"
  filename_numbers = "number.txt"
  
  queue_entity = asyncio.Queue()
  numbers = []
  count_thread = 8
  def load_numbers(filename):
      with open(filename, "r") as file:
          content = file.read().split("\n")
          for conten in content:
              numbers.append(conten)
  
  def load_excel(output_filename):
      data = pd.read_excel(output_filename, 'Projects', dtype=str)
      for item in data["Telegram link"]:
          if item != "nan":
              queue_entity.put_nowait(item)
  
  
  async def create_client(number):
      print(number)
      client = TelegramClient(number, api_id, api_hash).start()
      return client
  
  async def parse_entity(entity, client_coroutine):
      result = None
      client = await client_coroutine
      try:
          result = client(functions.channels.GetFullChannelRequest(
                  channel=entity
              ))
          print("Успешно")
      except TypeError:
          try:
              result = client(functions.users.GetFullUserRequest(
                  id=entity
              ))
          except TypeError:
              result = client(functions.messages.GetFullChatRequest(
                  chat_id=entity
              ))
      except errors.UsernameInvalidError:
          print("Не найден пользователь, канал или чат")
      except errors.InviteHashExpiredError:
          print("Чата больше нет")
      except errors.InviteHashInvalidError:
          print("Ссылка приглашения не валидна")
      except ValueError:
          print("Невозможно получить entity. Для начала нужно вступить в группу или чат")
      except errors.FloodWaitError:
          print("Ожидание суток")
      return result
  
  
  async def crawl(future):
      futures = []
      numbers = await future
      for client in asyncio.as_completed([create_client(number) for number in numbers]):
          while queue_entity.qsize() &gt; 0:
              futures.append(asyncio.ensure_future(parse_entity(queue_entity.get_nowait(), client)))
      if futures:
          await asyncio.wait(futures)
  
  async def start_main(root):
      print(root)
      loop = asyncio.get_event_loop()
      initial_future = loop.create_future()
      initial_future.set_result(root)
      await crawl(initial_future)
  
  if __name__ == '__main__':
      start = time.time()
      load_numbers(filename_numbers) #Загрузка телефонов
      load_excel(filename_excel)     #Загрузка Excel
      loop = asyncio.get_event_loop()
      # loop.set_debug(True)
      try:
          loop.run_until_complete(start_main(numbers))
      except KeyboardInterrupt:
          for task in asyncio.Task.all_tasks():
              task.cancel()
              with suppress(asyncio.CancelledError):
                  loop.run_until_complete(task)
      finally:
          loop.close()
      log.info("Time work: %s", time.time() - start)
  </code></pre>
  
  <p>In my regional forum, no one could help me, so I am writing here, since the English community is more, someone can help</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "D:/Git/telegram/telegram_new.py", line 54, in parse_entity
      result = client(functions.users.GetFullUserRequest(id=entity))
  TypeError: 'coroutine' object is not callable
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <pre><code>future: &lt;Task finished coro=&lt;parse_entity() done, defined at D:/Git/telegram/telegram_new.py:45&gt; exception=RuntimeError('coroutine is being awaited already')&gt;
  </code></pre>
  
  <p><strong>Update 3</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "D:/Git/telegram/telegram_new.py", line 95, in &lt;module&gt;
      loop.run_until_complete(start_main(numbers))
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 568, in run_until_complete
      return future.result()
    File "D:/Git/telegram/telegram_new.py", line 86, in start_main
      await crawl(initial_future)
    File "D:/Git/telegram/telegram_new.py", line 75, in crawl
      for client in asyncio.as_completed([await create_client(number) for number in numbers]):
    File "C:\ProgramData\Anaconda3\lib\asyncio\tasks.py", line 505, in as_completed
      todo = {ensure_future(f, loop=loop) for f in set(fs)}
    File "C:\ProgramData\Anaconda3\lib\asyncio\tasks.py", line 505, in &lt;setcomp&gt;
      todo = {ensure_future(f, loop=loop) for f in set(fs)}
    File "C:\ProgramData\Anaconda3\lib\asyncio\tasks.py", line 588, in ensure_future
      raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
  TypeError: An asyncio.Future, a coroutine or an awaitable is required
  2018-12-27 18:14:49,534 ERROR:Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;UpdateMethods._update_loop() running at C:\ProgramData\Anaconda3\lib\site-packages\telethon\client\updates.py:215&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x000001A379824108&gt;()]&gt;&gt;
  2018-12-27 18:14:49,534 ERROR:Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;MTProtoSender._send_loop() running at C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\mtprotosender.py:375&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x000001A379824138&gt;()]&gt;&gt;
  2018-12-27 18:14:49,534 ERROR:Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;MTProtoSender._recv_loop() running at C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\mtprotosender.py:413&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x000001A3798242B8&gt;()]&gt;&gt;
  Exception ignored in: &lt;coroutine object MTProtoSender._recv_loop at 0x000001A37980A948&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\mtprotosender.py", line 413, in _recv_loop
    File "C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py", line 123, in recv
    File "C:\ProgramData\Anaconda3\lib\asyncio\queues.py", line 161, in get
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 672, in call_soon
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 461, in _check_closed
  RuntimeError: Event loop is closed
  2018-12-27 18:14:49,534 ERROR:Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;Connection._send_loop() running at C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py:135&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x000001A379824228&gt;()]&gt;&gt;
  2018-12-27 18:14:49,534 ERROR:Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;Connection._recv_loop() running at C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py:150&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x000001A379824288&gt;()]&gt;&gt;
  2018-12-27 18:14:49,535 ERROR:Unexpected exception in the send loop
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\asyncio\queues.py", line 159, in get
      await getter
  GeneratorExit
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py", line 135, in _send_loop
      self._send(await self._send_queue.get())
    File "C:\ProgramData\Anaconda3\lib\asyncio\queues.py", line 161, in get
      getter.cancel()  # Just in case getter is not done yet.
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 672, in call_soon
      self._check_closed()
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 461, in _check_closed
      raise RuntimeError('Event loop is closed')
  RuntimeError: Event loop is closed
  Exception ignored in: &lt;coroutine object Connection._send_loop at 0x000001A37980AA48&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py", line 142, in _send_loop
    File "C:\ProgramData\Anaconda3\lib\site-packages\telethon\network\connection\connection.py", line 94, in disconnect
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 672, in call_soon
    File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 461, in _check_closed
  RuntimeError: Event loop is closed
  </code></pre>