Skip to content

UC keeps crashing on linux with FastAPI #2069

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

Closed
Willshears opened this issue Sep 7, 2023 · 1 comment
Closed

UC keeps crashing on linux with FastAPI #2069

Willshears opened this issue Sep 7, 2023 · 1 comment
Labels
duplicate The answer/solution already exists somewhere external Outside SeleniumBase's scope. / Ask somewhere else. UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@Willshears
Copy link

It runs fine on my Windows dev machine - when I run the program it automatically downloads the latest UC driver and works straight away. Now I'm trying to get it onto a prod environment with DigitalOcean apps and Docker. When I first run the script, it returns:

[2023-09-07 08:28:34] Extracting ['chromedriver'] from chromedriver-linux64.zip
[2023-09-07 08:28:35] Unzip Complete!
[2023-09-07 08:28:35] The file [uc_driver] was saved to:
[2023-09-07 08:28:35] /usr/local/lib/python3.10/site-packages/seleniumbase/drivers/uc_driver
[2023-09-07 08:28:35] Making [uc_driver 116.0.5845.96] executable ...
[2023-09-07 08:28:35] [uc_driver 116.0.5845.96] is now ready for use!

However, it hangs for a while and eventually responds with:
[2023-09-07 08:30:46] selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:9222 and (The process started from chrome location /root/.cache/selenium/chrome/linux64/116.0.5845.96/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Here's my dockerfile:

# Use the Python 3.10 slim image
FROM ubuntu:18.04
FROM python:3.10.4

# Installing necessary utilities first
RUN apt-get update && \
    apt-get install -y wget curl gnupg jq unzip libnss3 libxi6 xvfb vim libgconf-2-4 libxcb1 libglib2.0-0 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN CHROME_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chrome[] | select(.platform == "linux64") | .url') \
    && curl -sSLf --retry 3 --output /tmp/chrome-linux64.zip "$CHROME_URL" \
    && unzip /tmp/chrome-linux64.zip -d /opt \
    && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \
    && chmod +x /usr/local/bin/chrome \
    && rm /tmp/chrome-linux64.zip

# Set environment variables
ENV PYTHONUNBUFFERED 1
ENV DISPLAY=:99

RUN export PYTHONIOENCODING=utf8
RUN echo "export PYTHONIOENCODING=utf8" >> ~/.bashrc

# Create and set the working directory
WORKDIR /app

# Copy the current directory (your FastAPI project) into the container at /app
COPY . .

COPY ./requirements.txt /requirements.txt

# Install any other dependencies for your FastAPI project
RUN pip install --no-cache-dir -r requirements.txt

Here's how the driver is being configured:
driver = Driver(uc=True, proxy=proxy, protocol="https", headless=True, no_sandbox=True, disable_gpu=True)

I can't tell if it's FastAPI, undetected chromedriver or the server itself responsible. Any help would be appreciated! thanks.

@mdmintz mdmintz added duplicate The answer/solution already exists somewhere external Outside SeleniumBase's scope. / Ask somewhere else. UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Sep 7, 2023
@mdmintz
Copy link
Member

mdmintz commented Sep 7, 2023

Duplicate of #2030 (comment)

(See the solution posted there)

@mdmintz mdmintz closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere external Outside SeleniumBase's scope. / Ask somewhere else. UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants