SergeyPirogov / webdriver_manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChromeDriverManager().install() throws PermissionError

mwalaszkowski opened this issue · comments

I try initialize chrome web driver. To do this i using below method:

driver = webdriver.Chrome(service=Service(executable_path=ChromeDriverManager().install()),
                                  options=driver_options)

When i executing this inside docker container I've got this error message:

venv/lib/python3.9/site-packages/webdriver_manager/chrome.py:40: in install
    driver_path = self._get_driver_binary_path(self.driver)
venv/lib/python3.9/site-packages/webdriver_manager/core/manager.py:41: in _get_driver_binary_path
    binary_path = self._cache_manager.save_file_to_cache(driver, file)
venv/lib/python3.9/site-packages/webdriver_manager/core/driver_cache.py:53: in save_file_to_cache
    archive = self.save_archive_file(file, path)
venv/lib/python3.9/site-packages/webdriver_manager/core/driver_cache.py:46: in save_archive_file
    return self._file_manager.save_archive_file(file, path)
venv/lib/python3.9/site-packages/webdriver_manager/core/file_manager.py:45: in save_archive_file
    os.makedirs(directory, exist_ok=True)
/usr/local/lib/python3.9/os.py:215: in makedirs
    makedirs(head, exist_ok=exist_ok)
/usr/local/lib/python3.9/os.py:215: in makedirs
    makedirs(head, exist_ok=exist_ok)
/usr/local/lib/python3.9/os.py:215: in makedirs
    makedirs(head, exist_ok=exist_ok)
/usr/local/lib/python3.9/os.py:215: in makedirs
    makedirs(head, exist_ok=exist_ok)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = '/.wdm', mode = 511, exist_ok = True

    def makedirs(name, mode=0o777, exist_ok=False):
        """makedirs(name [, mode=0o777][, exist_ok=False])

        Super-mkdir; create a leaf directory and all intermediate ones.  Works like
        mkdir, except that any intermediate path segment (not just the rightmost)
        will be created if it does not exist. If the target directory already
        exists, raise an OSError if exist_ok is False. Otherwise no exception is
        raised.  This is recursive.

        """
        head, tail = path.split(name)
        if not tail:
            head, tail = path.split(head)
        if head and tail and not path.exists(head):
            try:
                makedirs(head, exist_ok=exist_ok)
            except FileExistsError:
                # Defeats race condition when another thread created the path
                pass
            cdir = curdir
            if isinstance(tail, bytes):
                cdir = bytes(curdir, 'ASCII')
            if tail == cdir:           # xxx/newdir/. exists if xxx/newdir exists
                return
        try:
>           mkdir(name, mode)
E           PermissionError: [Errno 13] Permission denied: '/.wdm'

In some older version of selenium and webdriver manager this code works fine.
Can someone help me with this issue?

OS: linux
webdriver-manager==4.0.1
selenium==4.14.0
python 3.9

the user associated with the container needs write and execute access in order to download and save the chrome driver. if name = '/.wdm' then it needs to be able to write to the root. Fastest way to confirm this is the issue is run the service with the user as root

...
    # Add a User
    user: root
...

Issue is still visible when I add USER ROOT inside Dockerfile and run container in privilege mode

@mwalaszkowski I needed to use USER root or I got errors.

@david-engelmann i am having this issue also when running this from uwsgi process (via a selenium project), is there a way to force the driver installer to put the driver somewhere else where we can have permissions ? (i can't see it in the docs)
/root works when running a standalone python script. But i can't run uwsgi as root since that is a total risk.

@moda20

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install(path="path_to_save_to")))