[Python] ImportAuthorizationRequest function does not authorize the client, although it does...

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    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


    this code returns None at the end, although it should return User(...) why the session does not become authorized if ImportAuthorizationRequest works without errors

    I checked, the function returns the Authorization() object, which corresponds to the confirmed authorization, but the authorization itself is not in the list of devices, nor in the .session file

    new_client.session.set_dc(
    dc_id=target_dc_id, server_address=new_client.session.server_address, port=new_client.session.port
    )


    I tried to write dc_id at the end

    Continue reading...

Compartilhe esta Página