Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"You cannot reuse the ChromeOptions object" error only when running in docker #2001

Open
ttraxxrepo opened this issue Aug 31, 2024 · 0 comments

Comments

@ttraxxrepo
Copy link

ttraxxrepo commented Aug 31, 2024

I've written a class that automatically starts a new instance (and should be instantiating new chromeOptions) every time the Bot.run() command is called

from seleniumbase import SB

class Bot():
    def run(self):
            with SB(uc=True, user_data_dir=self.user_data_dir_path) as sb:
                  # program code

This code works fine when I run it locally in venv, however it does not work when running the same code in a docker container with a mounted /used_data_dir volume (self.user_data_dir_path) for persistency.

Some additional findings I've discovered while testing:

  1. In docker, the code works fine for the first run when the user_data_dir does not yet exist
  2. In docker, the code works for additional runs leveraging the user_data_dir that gets created from the initial run if the container has not been stopped yet
  3. If the container is restarted (docker restart or docker stop && docker start) the code still works
  4. Only when the container is destroyed and then spun up again (docker down && docker up) does the "You cannot reuse the ChromeOptions object" error get thrown

Could you please help me understand why I am experiencing this behavior and how to resolve?

I recognize SeleniumBase is a separate repo I am leveraging, however the maintainer of that repo has sent me here as it seems to be the undetected_chromedriver portion that is throwing the error

I saw #555, however because the above context manager recreates a new instance every time and this code does work in venv and not docker, do not think its related.

Thanks in advance!

Dockerfie:

FROM ghcr.io/cascandaliato/seleniumbase:master

# Install necessary packages
RUN apt-get update && \
    apt-get install --yes git ffmpeg

# Copy main application code into the root directory
COPY . /

# Install Python dependencies for the main application
RUN pip install -U pip && pip install -r requirements.txt

ENTRYPOINT ["python3", "main.py"]

docker-compose.yml:

services:
  botscraper:
    container_name: botscraper
    privileged: true
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - "Python Projects/botscraper/user_data_dir:/user_data_dir"
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - TZ=America/New_York
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant