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

Chrome Driver initialization Error - Multiprocessing Error returned when ran from Docker #740

Closed
Sagaryal opened this issue Jul 23, 2022 · 3 comments

Comments

@Sagaryal
Copy link

Sagaryal commented Jul 23, 2022

The below code works fine when running locally using virtualenv. But when I dockerized it, an error is received. As I debugged it seems the error is from driver = uc.Chrome(headless=True)

Python Versions tried: 3.10, 3.8

import json
from fastapi import FastAPI
import undetected_chromedriver.v2 as uc
from selenium.webdriver.common.by import By
from utils import Item

app = FastAPI()
print('Before Chrome Initiasation ------>')
driver = uc.Chrome(headless=True)
print('After Chrome Initiasation ------>')


@app.post("/")
def root(item: Item):
    # known url using cloudflare's "under attack mode"
    # driver.get(item.url)
    # html = driver.find_element(By.TAG_NAME, 'html').text

    return "This is return data"

Error:

Attaching to scrapper
scrapper  | Before Chrome Initiasation ------>
scrapper  | Process Process-1:
scrapper  | Traceback (most recent call last):
scrapper  |   File "/usr/local/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
scrapper  |     self.run()
scrapper  |   File "/usr/local/lib/python3.10/multiprocessing/process.py", line 108, in run
scrapper  |     self._target(*self._args, **self._kwargs)
scrapper  |   File "/usr/local/lib/python3.10/site-packages/undetected_chromedriver/dprocess.py", line 59, in _start_detached
scrapper  |     p = Popen([executable, *args], stdin=PIPE, stdout=PIPE, stderr=PIPE, **kwargs)
scrapper  |   File "/usr/local/lib/python3.10/subprocess.py", line 969, in __init__
scrapper  |     self._execute_child(args, executable, preexec_fn, close_fds,
scrapper  |   File "/usr/local/lib/python3.10/subprocess.py", line 1720, in _execute_child
scrapper  |     and os.path.dirname(executable)
scrapper  |   File "/usr/local/lib/python3.10/posixpath.py", line 152, in dirname
scrapper  |     p = os.fspath(p)
scrapper  | TypeError: expected str, bytes or os.PathLike object, not NoneType

Dockerfile

FROM python:3.10

ENV PYTHONUNBUFFERED True

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

EXPOSE 8000

COPY . ./

CMD exec uvicorn main:app --host 0.0.0.0 --port 8000
@Sagaryal Sagaryal changed the title Multiprocessing Error returned when ran from Docker Chrome Driver initialization Error - Multiprocessing Error returned when ran from Docker Jul 23, 2022
@ultrafunkamsterdam
Copy link
Owner

you are trying to load plain html to json.

@Sagaryal
Copy link
Author

Sagaryal commented Jul 25, 2022

you are trying to load plain html to json.

@ultrafunkamsterdam Sir please do once check the above Edited code again. It's not because of plain html to json. As you can see even plain return response is not working.

Furthermore, the root() function executes only when API is called. But Chrome initialization is done before and code is not even running.

As you can see error logs. Before Chrome Initiasation ------> is being printed but not After Chrome Initiasation ------> which means that Chrome is not being initialized.

Also the error logs point out error in below line in your code:

File "/usr/local/lib/python3.10/site-packages/undetected_chromedriver/dprocess.py", line 59, in _start_detached
scrapper | p = Popen([executable, *args], stdin=PIPE, stdout=PIPE, stderr=PIPE, **kwargs)

Nevertheless, I have tried and edited the code and error response above for your reference.

Also Please do note that THIS IS WORKING in non-docker.

@pepi99
Copy link

pepi99 commented Jul 11, 2023

Did you solve it ?

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

3 participants