title: How to connect to Telegram using Telethon?
body: <p>maybe this is a recurrent topic however I looked before and found the list below that did not solved my problem:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/58590974/singing-in-telegramclient-telethon">Singing in TelegramClient telethon</a></li>
  <li><a href="https://stackoverflow.com/questions/58790772/when-starting-client-the-code-is-asking-for-phone-bot-token">When starting client the code is asking for phone/bot token</a></li>
  <li><a href="https://stackoverflow.com/questions/61884537/hosting-a-telethon-user-bot-on-google-app-engine">Hosting a Telethon User BOT on google-app-engine</a></li>
  <li><a href="https://stackoverflow.com/questions/62016386/how-to-search-for-groups-and-channel-in-telegram-using-telethon">How to search for groups and channel in telegram using telethon?</a></li>
  </ul>
  <p>So far none of those solutions helped me.</p>
  <ul>
  <li>I am not using 2FA on Telegram</li>
  </ul>
  <p>My code is like below</p>
  <pre><code>import configparser
  import json
  import asyncio
  import nest_asyncio
  from datetime import date, datetime
  
  from telethon import TelegramClient, sync, functions
  from telethon.errors import SessionPasswordNeededError
  from telethon.tl.functions.messages import (GetHistoryRequest)
  from telethon.tl.functions.contacts import ResolveUsernameRequest
  from telethon.tl.types import (PeerChannel)
  nest_asyncio.apply()
  
  # some functions to parse json date
  class DateTimeEncoder(json.JSONEncoder):
      def default(self, o):
          if isinstance(o, datetime):
              return o.isoformat()
  
          if isinstance(o, bytes):
              return list(o)
  
          return json.JSONEncoder.default(self, o)
      
  class MyBot:
      api_id = None
      api_hash = None
      phone = None
      username = None
      channel = None
      debug = &quot;False&quot;
      client = None
      loaded = &quot;False&quot;
        
      def readConfig (self):
          config = configparser.ConfigParser()
          config.read(&quot;config.ini&quot;)
          
          # Setting configuration values
          self.api_id = config['Telegram']['api_id']
          self.api_hash = config['Telegram']['api_hash']
          
          self.api_hash = str(self.api_hash)
          
          self.phone = config['Telegram']['phone']
          self.username = config['Telegram']['username']
          
          self.channel = config['Telegram']['channel']
          self.debug = config['Telegram']['debug']
          if self.api_id != None:
              if self.api_hash != None:
                  if self.phone != None:
                      if self.username != None:
                          if self.channel != None:
                              self.loaded = &quot;True&quot;
      
      def printConfig (self):
          if self.debug == &quot;True&quot;:
              print(&quot;api_id: &quot;+self.api_id)
              print(&quot;api_hash: &quot;+self.api_hash)
              print(&quot;phone: &quot;+self.phone)
              print(&quot;username: &quot;+self.username)
          else: print(&quot;Debug if False&quot;)
      
      async def createClient(self):
          if self.loaded == &quot;True&quot;:
              print(&quot;Creating Client&quot;)
              client = TelegramClient(session=&quot;session&quot;, api_id =self.api_id, api_hash =self.api_hash)
              await client.start()
              # Ensure you're authorized
              if not await client.is_user_authorized():
                  await client.send_code_request(self.phone)
                  try:
                      await client.sign_in(self.phone, input('Enter the code: '))
                  except SessionPasswordNeededError:
                      await client.sign_in(password=input('Password: '))
          
              search = 'linux'
              result = await client(functions.contacts.SearchRequest(
                  q=search,
                  limit=100
              ))
              print(result.stringify())            
  
  myBot = MyBot()
  myBot .readConfig()
  myBot .printConfig()
  #myBot .createClient()
  asyncio.ensure_future(myBot .createClient())
  </code></pre>
  <p>I also have a config.ini file on the same folder as this code with the alraedy setup for my credentials to use the Telegram API.</p>
  <p>When I run this code it returns</p>
  <ul>
  <li>api_id: 1234567 (fake value here)</li>
  <li>api_hash: xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy</li>
  <li>phone: +</li>
  <li>username: @myIdonTelegram</li>
  <li>Creating Client</li>
  <li>Please enter your phone (or bot token):</li>
  </ul>
  <p>I can't escape this prompt asking me my phone and even if i type it nothing happens
  What am I missing? Why it keeps me asking my phone and how to by pass it?</p>