Skip to content

Driver doesn't work on odoo 18 #2257

@badrbnh

Description

@badrbnh

Hello community.

I am trying to scrap a website from a model in odoo. It get executed using an action button.
I am using Docker to contain the app.
However the driver never worked for me, even with normal selenium so I had to use selenium grid.
Now I am facing a cloudflare protected website, I needed a to use undetected chromedriver.

My code works fine using a normal script, but from an odoo model it doesn't get to work.

Error

Message: Service /var/lib/odoo/.local/share/undetected_chromedriver/undetected_chromedriver unexpectedly exited. Status code was: -5

Code

`def _get_chrome_driver(self):
# Set up Chrome options for better stability
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-software-rasterizer')
chrome_options.add_argument('--disable-setuid-sandbox')
chrome_options.add_argument('--headless=new')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument(
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36')

    try:
        #Creating driver by connecting to remote Selenium Grid Hub instead of local chrome
        driver = uc.Chrome(
            options=chrome_options,
        )
        _logger.info("Successfully connected to Selenium Grid Hub")
        return driver
    except WebDriverException as e:
        _logger.error(f"Failed to create Chrome driver: {str(e)}")
        raise`

Dockerfile

`FROM odoo:18

USER root

RUN apt-get update && apt-get install -y
wget
unzip
gnupg
curl
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub
| gpg --dearmor > /etc/apt/trusted.gpg.d/google-chrome.gpg
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
> /etc/apt/sources.list.d/google-chrome.list
&& apt-get update && apt-get install -y
google-chrome-stable
chromium-driver
&& rm -rf /var/lib/apt/lists/*

COPY ./requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt --break-system-packages --ignore-installed

ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

USER odoo`

If any odoo developers or who faced that problem before, please help me. I appreciate it.

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