python-3.x Telethon(Telegram lib)给我的会话无

e3bfsja2  于 2023-03-24  发布在  Python
关注(0)|答案(1)|浏览(134)

当我尝试保存会话时,它给我的会话值为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())
zsohkypk

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)

相关问题