[Python] SessionNotCreatedException when launching Selenium ChromeDriver with FastAPI Slack...

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

  1. Stack

    Stack Membro Participativo

    I have a FastAPI server with a Slack chatbot that launches Selenium for automating certain tasks. However, I'm encountering an issue when initializing the ChromeDriver with the --user-data-dir argument:

    user_data_dir = tempfile.mkdtemp()
    chrome_options.add_argument(f"--user-data-dir={user_data_dir}")

    # Initializing the driver
    driver = webdriver.Chrome(options=chrome_options)


    When I run this, it fails with the following error:

    selenium.common.exceptions.SessionNotCreatedException: Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir


    When I connect on ssh to the server it works without doing nothing.

    I tried change the path:

    chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")


    I tried static path

    chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")


    And I have always the same behaviour.

    I use AWS Lightsail with Ubuntu 22.04.5 LTS

    Continue reading...

Compartilhe esta Página