i use this script for connect and create sessions in telethon
from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryReques
from telethon import TelegramClient
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = ****** # Your api_id
api_hash = '********************************' # Your api_hash
phone_number = '+989122594574' # Your phone number
client = TelegramClient(phone_number, api_id, api_hash)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone_number)
client.sign_in(phone_number, input('Enter the code: '))
client.send_message('amir2b', 'Hello! Amir Bashiri')