Reputation: 69
On my main Windows 10 computer I originally made a python flask app to scrape a website for shows to watch and the page required rendering for the javascript im assuming. So, I went with request-html in python which uses pyppeteer.
Now I'm trying to get it over on docker and I either get errors unable to find Chromium or just hanging after the Chromium download when it runs in python for the first time.
The python version of puppeteer must be different because it usually ignores the ENV variables I put like PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
and PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
Here is the current state of my dockerfile:
FROM python:3.11-alpine
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont \
nodejs \
npm
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
COPY run.py ./
COPY app ./app
CMD ["python", "run.py"]
This only doesn't have problems finding Chromium or freezing if I add in this stuff in python:
from pyppeteer import launch
browser = await launch({
'executablePath': os.getenv('PUPPETEER_EXECUTABLE_PATH', '/usr/bin/chromium-browser'),
'headless': True,
'args': [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-gpu',
'--single-process',
'--no-zygote'
]
})
This is my most successful run and now I'm just lost. Am I missing some other dependencies or setup? I tried adding puppeteer through yarn with the same error RUN yarn add [email protected]
browser = await launch({
File "/usr/local/lib/python3.11/site-packages/pyppeteer/launcher.py", line 307, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.11/site-packages/pyppeteer/launcher.py", line 168, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/usr/local/lib/python3.11/site-packages/pyppeteer/launcher.py", line 227, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:
If something else would work better please let me know.
Upvotes: 0
Views: 224