Skip to content

TDataSession.from_tdata ignores API credentials from tdata folder #24

@azamtoiri

Description

@azamtoiri

The TDataSession.from_tdata() method currently ignores the API credentials (api_id, api_hash, device_model, etc.) stored in the tdata folder and instead uses the default API.TelegramDesktop values.

Current Behavior:

@classmethod
def from_tdata(cls, tdata_folder: Union[Path, str]):
    tdata_folder = Path(tdata_folder)
    if not tdata_folder.exists():
        raise FileNotFoundError(tdata_folder)
    client = TDesktop(basePath=tdata_folder)
    account = client.mainAccount
    return cls(
        auth_key=account.authKey.key,
        user_id=account.UserId,
        dc_id=account.MainDcId
        # api parameter is not passed, so default API.TelegramDesktop is used
    )

Expected Behavior:

The method should extract and use the actual API credentials from the tdata folder via client.api:

return cls(
    auth_key=account.authKey.key,
    user_id=account.UserId,
    dc_id=account.MainDcId,
    api=client.api  # Use actual API from tdata
)

Impact:

When converting tdata sessions to Pyrogram/Telethon, the resulting session uses incorrect API credentials, which can cause:

  • Authentication failures
  • API ID mismatches with the original session
  • Potential account restrictions

Workaround:

Manually create SessionManager with correct API:

desk = TDesktop(str(tdata_path))
session_manager = SessionManager(
    dc_id=desk.mainAccount.MainDcId,
    auth_key=desk.mainAccount.authKey.key,
    user_id=desk.mainAccount.UserId,
    api=desk.api
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions