当我尝试保存会话时,它给我的会话值为None
from telethon.sync import TelegramClient,events
import datetime
# from .telegram_config import App_api_id,App_api_hash
api_id = '*******'
api_hash = "**********"
phone_number = '+*************'
# Create a new TelegramClient with the specified session file path, API ID, and API hash
client = TelegramClient("session", api_id, api_hash)
# Start the client and establish a connection to the Telegram API using the specified phone number
client.start(phone=phone_number)
# Print the session string to the console
print(client.session.save())
1条答案
按热度按时间zsohkypk1#
你可以使用下面的代码生成会话
从telethon.sync导入TelegramClient,事件
从telethon.sessions导入StringSession
API_id = ''
API_hash =“****”
电话号码= '**'
使用指定的会话文件路径、API ID和API哈希创建新的TelegramClient
client = TelegramClient(StringSession(),API_id,api_hash)
启动客户端并使用指定的电话号码建立与Telegram API的连接
client.start(phone=phone_number)