"Webdrivers"可执行文件可能具有错误的权限。请参见https://sites.google.com/a/chromium.org/chromedriver/home。

50

我已经查看了文档,但并没有找到答案。

我一直在尝试使用InstaPy,这是一个Python的Instagram API。在多次失败和无法解决错误后,我假设InstaPy可能存在一些问题,所以我试图使用Selinium编写原始代码。在插入示例代码并根据自己的喜好进行更改后,我确保此代码有效。但是,与旧错误不同,我收到了新的错误消息,指出权限可能不正确。我尝试过重新安装和以管理员身份运行,但都没有效果。我该如何解决这个问题,或者这意味着什么?

代码:

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()

错误:

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
22个回答

97

这个错误信息...

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

这意味着你正在尝试使用的ChromeDriver变体具有错误的权限。

你似乎尝试过:

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

一些话:
  • If your underlying is :

    • 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 is :

    • 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 is :

    • 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')
      

3
在Windows 10和Python 3.7.1上,我不需要使用原始(r)开关。也不需要'executable_path='。不太确定为什么,下面的链接表明os.path.normpath可以纠正这个问题。可能这种做法已经包含在了webdriver.Chrome()中。https://pythonconquerstheuniverse.wordpress.com/2008/06/04/gotcha-%E2%80%94-backslashes-in-windows-filenames/ - CodingMatters

25

当您输入完整的文件名“chromedriver.exe”时,问题将得到解决。如果您使用的是Windows系统,请尝试此方法。


8
Ubuntu 怎么样? - Mostafa
4
ChromeDriver,没有.exe文件。 - Snow

8

您只需在路径末尾添加

/chromedriver.exe

就像这样:

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

注意:如果您从“文件资源管理器”中复制路径,则会得到:

C:\Users\User\Downloads\chromedriver_win32

您需要使用双反斜杠,像这样:

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

以避免出现语法错误。或者,您也可以使用正斜杠。


7

如果您正在使用Linux操作系统,更改文件权限可能会修复该问题。但请注意,权限的使用非常重要:

chmod 755 "/path to chromedriver file"

我通过Python本身下载了该文件,但不幸的是,它禁用了执行权限,这是解决它的快速方法。


4
在Linux中,您需要指定完整路径,包括文件本身,而不仅仅是文件夹(在Linux中,默认情况下chrome driver的下载文件位于文件夹中,例如'chromedriver_linux64',打开文件夹并检查确切的文件名,通常为'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")

1
这个回复没有得到应有的关注。谢谢! - milia

2
如果您使用的是Mac OS Big Sur和Chromedriver90+,可能会遇到与Chromedriver权限有关的错误。
如果是这种情况,那么您不需要通过"chmod"更改文件权限,而是需要解除苹果商店的保护,以允许执行web驱动程序。
如果想要让该驱动程序在Python环境或命令行中使用,请输入:
`$ sudo xattr -r -d com.apple.quarantine  /usr/local/bin/chromedriver`

2
如果您正在使用Chrome,您必须指定chromedriver的完整路径。搜索包含chromedriver可执行文件的目录。在可执行文件上按Shift +右键。选择“复制为路径”并将其粘贴到您的脚本中。不要忘记使用双反斜杠。
因此应该是:
driver = webdriver.Chrome('C:\\Utility\\BrowserDrivers\\chromedriver.exe')

1

WINDOWS:给出完整的文件路径可以解决问题。

许多教程和文章都是使用旧版本记录的,其中您只需提供包含 Web 驱动程序的目录路径即可。但现在您还需要提供正在使用的特定驱动程序路径。

与其使用 C:/WebDrivers,不如使用完整的文件路径,例如 C:/WebDrivers/chromedriver.exe


1
相同的问题。我的解决方案是在Linux操作系统下,使用Pycharm编辑器...
  1. 确保您的webdriver文件与其他Python文件(例如selinum_driver.py)一起
  2. 然后只需复制路径并将其粘贴到webdriver.Chrome('path')中
  3. 不需要编写webdriver.exe

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


1

针对WINDOWS 10:在使用Visual Studio Code运行测试代码时,我遇到了类似的错误提示。解决方法是关闭VS Code应用程序并通过右键菜单以管理员身份重新打开应用程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接