• Uncategorized

About python : Webdrivers-executable-may-have-wrong-permissions-Please-see-httpssitesgooglecomachromiumorgchromedriverhome

Question Detail

I’ve looked around checked both documentations and have found no answer.

I’ve been trying to use InstaPy a instagram api for python. After failing with multiple errors and assuming InstaPy is just having some issues so i tried to raw code it using selinium. after inserting the example code and alter it to my liking i just made sure this one would work. I received a new error instead of the old one saying the permissions may not be right. I have tried reinstall and running as admin but nothing works. how do i fix this and/or what does this mean

Code:

import time
from selenium import webdriver

driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()

Error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Webdrivers\RawBot.py", line 5, in <module>
    driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search path.
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Question Answer

This error message…

WebDriverException: Message: 'Webdrivers' executable may have wrong permissions.

…implies that the ChromeDriver variant you are trying to use have wrong permissions.


You seem to have tried out:

driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search system $PATH variable.

A few words:

  • If your underlying os is windows:

    • You have to download chromedriver_win32.zip from the ChromeDriver Download Location and unzip it for usage.
    • Additionally, if you are explicitly specifying the Chromedriver binary path you have to append the binary extension as well, effectively i.e. chromedriver.exe.
    • While mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\\).
    • So your effective line of code will be :

      driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
      
  • If your underlying os is linux:

    • You have to download chromedriver_linux64 from the ChromeDriver Download Location and untar it for usage.
    • Additionally, if you are explicitly specifying the Chromedriver binary path you don’t have to provide any extension for the executable binary, effectively i.e. chromedriver.
    • While mentioning the Chromedriver binary path you have to use the single forward slash i.e. (/).
    • So your effective line of code will be :

      driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
      
  • If your underlying os is macos:

    • You have to download chromedriver_mac64 from the ChromeDriver Download Location and untar it for usage.
    • Additionally, if you are explicitly specifying the Chromedriver binary path you don’t have to provide any extension for the executable binary, effectively i.e. chromedriver.
    • While mentioning the chromedriver binary path you have to use the single forward slash i.e. (/).
    • So your effective line of code will be :

      driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
      

This got solved when you enter the full file name which is “chromedriver.exe”. Try this if you are on windows

You just have to add

/chromedriver.exe

at the end of the path like this:

driver = webdriver.Chrome('C:/Users/User/Downloads/chromedriver_win32/chromedriver.exe')

Note: If you copy the path from “File Explorer” you will get:

C:\Users\User\Downloads\chromedriver_win32

You will need to use double backslashes like this:

C:\\Users\\User\\Downloads\\chromedriver_win32

so you don’t get a syntax error. Or you can just use forward slashes.

If you are on a linux os, changing file permissions could possibly fix the problem. But beware of what you do with permissions:

chmod 755 "/path to chromedriver file"

I downloaded the file via python itself, which unfortunately disabled execution permission and this was the quick fix for it.

if you are using chrome you must specify the full path of the chromedriver.
search for the directory in which your chromedriver executable file resides.
click shift+right click on the executable file.
select “copy as path” and paste it in your script.
don’t forget to use a double backslash

so it should be:

driver = webdriver.Chrome('C:\\Utility\\BrowserDrivers\\chromedriver.exe')

If you use a Mac OS Big Sur, and Chromedriver 90+, you might have an error with the permissions of your Chromedriver.

If this is the case, it’s not the file permissions that you change via “chmod,” instead, it is apple-store protection that forbids the execution of the web driver.

If you like to allow this driver to be used within your Python environment or via command-line, enter:

`$ sudo xattr -r -d com.apple.quarantine  /usr/local/bin/chromedriver`

had same issue in django.

However when I ran the same code locally (not activating my django app) it was fine and didn’t have to explicitly define the path to the chrome driver.

Got around it by explicitly defining the path and the chromederiver.exe

similar to the answer above.
path = “C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe”

in my case, since I want to eventually post my app I used dynamic paths

ie.

import os

BASE_oaAPP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_oaAPP_Utilities_DIR  = os.path.join(BASE_oaAPP_DIR, 'mySubFolderInTheApp')

def utilsPathFileName(fileName):
    return os.path.join(BASE_oaAPP_Utilities_DIR, fileName)

chrome_path = utilsPathFileName('chromedriver.exe')
driver = webdriver.Chrome(chrome_path)

WINDOWS : Giving complete file path solved problem.

Many tutorials and articles are recorded with previous versions, where you just give directory path containing web drivers. But now you also have to provide specific driver path you’re using.

Instead of C:/WebDrivers give complete file path as C:/WebDrivers/chromedriver.exe

chmod 755 "/path to chromedriver file"

This has helped me

The same problem. My solution was in Linux os, Pycharm editor…

  1. Make sure your webdriver file with other python files (such as selinum_driver.py)
  2. Then just copy the path and paste it into your webdriver.Chrome(‘path’)
  3. Don’t need to write webdriver.exe

driver = webdriver.Chrome('/home/raju/Documents/Python-selenium/chromedriver')

For WINDOWS 10: I ran into a similar situation with the same error message when running my test code in Visual Studio Code. What solved it for me was to close out of the VS Code app and re-open the app as an administrator via the right-click menu.

in Linux you need to specify the FULL path including the file itself as well, not just up to the folder (in Linux by default the downloaded file for chrome driver comes in a folder, e.g. ‘chromedriver_linux64’, open the folder and check the exact file name as well, usually ‘chromedriver’):

from selenium import webdriver
chrome_driver_path = "/home/mn/chromedriver_linux64/chromedriver"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("https://www.amazon.com")

For me, none of the answers above worked. But moving the chromedriver.exe to a new path (desktop in my case) solved it.

path = "C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe"

I got the same error when wrongly installed drives(when for mac was downloaded windows drivers) once I correct it worked fine

You need to add exe at the end of the path of driver and it works.

locate your installed driver.exe,
shift+right click,
copy as path,
paste it to your IDE

we can fix this issue for centos

#Install package chromedriver. Install it using yum    
yum install chromedriver

#Import following package in python.
from selenium import webdriver

#Add following options before initializing the webdriver
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=9222")
chromeOptions.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chromeOptions)

If you run it on a Windows computer you can also add it to Windows PATH (environment variables) so you don’t have to declare executable_path. You can just say: webdriver.Chrome(options=your_options)

I got his error for MacOs and on changing the path to the one given below, the issue was solved.

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')

I kept having this SAME problem after:

  • my script did not recognize chromdriver.exe in my $PATH (yes, it’s there)
  • gave run permissions to exe
  • passed ‘path/to/chromedriver.exe’ into Chrome()

This is what solved it:
Don’t give .exe in the python path(just provide up to the chromedriver in the path)

example:

driver = webdriver.Chrome("/Library/Frameworks/Python.framework/.../webdriver/chrome/chromedriver")

Unfortunately I still cant’ get my script to read the chromedriver.exe path from my $PATH variable. Would still appreciate if someone helped out, although it’s beyond the scope of this question

Windows users and visual studio code: while mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\).
as well use the exact path and add chromedriver.exe at the end of the path to point directly to the executable:

driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')

or:

driver = webdriver.Chrome(r'C:\\Users\\wanja\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe')

this error means that file chromedriver is not executable,
I fix this error with run command of (in linux):

sudo chmod +777 chromedriver

It means to make the file executable by everyone with access.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.