Skip to content

ImportAuthorizationRequest doesnt work #4691

@zvezda111

Description

@zvezda111

Code that causes the issue

async def clone_session(
self,
proxy: any,
json_file_path: Path,
client: TelegramClient,
clone_dir: Path,
) -> Tuple[bool, Optional[str]]:

    logger.info(f"Starting session cloning process")
    logger.info(f"JSON file: {json_file_path}")
    logger.info(f"Clone directory: {clone_dir}")


    json_file = json_file_path

    if not json_file:
        logger.error(error_msg)
        return False, error_msg
    account_data = load_account_data(json_file)
    if not account_data:
        error_msg = f"Failed to load account data from {json_file}"
        logger.error(error_msg)
        return False, error_msg
    api_id = account_data.get('app_id')
    api_hash = account_data.get('app_hash')
    if not api_id or not api_hash:
        error_msg = f"Missing app_id or app_hash in {json_file}"
        logger.error(error_msg)
        return False, error_msg
    logger.info(f"Using API ID: {api_id}")
    logger.debug(f"Using API Hash: {api_hash[:10]}...")

    logger.info("Connecting to original session...")
    original_client = client
    await original_client.connect()
    aut = await original_client.is_user_authorized()
    if not aut:
        error_msg = "Original session is not authorized"
        logger.error(error_msg)
        await original_client.disconnect()
        return False, error_msg
    logger.info("Original session connected successfully")
    me = await original_client.get_me()
    if not me:
        error_msg = "Original session is not authorized"
        logger.error(error_msg)
        await original_client.disconnect()
        return False, error_msg
    logger.info(f"Original session user: {me.first_name} (@{me.username})")
    logger.info("Creating new session using invisible login method...")
    config = await original_client(functions.help.GetConfigRequest())
    dc_id = config.dc_options[0].id  # Выберите подходящий DC
    logger.info(f"Using DC: {dc_id}")
    auth_data = await original_client(functions.auth.ExportAuthorizationRequest(dc_id=2))
    logger.info("Token created!")
    new_client = TelegramClient(f'cloned\\{me.phone}', api_id, api_hash, proxy=None, 
            device_model='Edge 117.0.2045.47',
            system_version='Windows',
            app_version='10.9.56 A',
            system_lang_code='en-us',
            lang_code='en'
            )
    await new_client.connect()
    await new_client(functions.auth.ImportAuthorizationRequest(id=auth_data.id, bytes=auth_data.bytes))
    logger.info("Authorization imported successfully")
    me = await new_client.get_me()
    print(me)
    print(me)
    print(me)
    print(me)

    
    return True, None

Expected behavior

print(me) write User(....)

Actual behavior

print(me) should not write None, ImportAuthorizationRequest returns Authorization, but the session continues to be unauthorized

Traceback

No response

Telethon version

1.40

Python version

3.13.0

Operating system (including distribution name and version)

Windows 10

Other details

This code should create a new session from the old one, but it does not work (no need via QR\code)

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions