【问题标题】:PermissionError: [Errno 13] Permission denied: '/content/' Message: '' executable may have wrong permissions on Google-Colabotory with Selenium PythonPermissionError: [Errno 13] Permission denied: '/content/' Message: '' executable may have wrong permissions on Google-Colabotory with Selenium Python
【发布时间】:2020-04-03 23:36:28
【问题描述】:

我一直在为我的 python 项目使用 Google Colab。我想使用 Google Colab 学习和实现 Selenium。我正在尝试登录 Facebook,如下所示。但是,我被“权限错误”困住了。我查看了各种帖子并尝试执行建议的解决方案,例如 (Selenium on MAC, Message: 'chromedriver' executable may have wrong permissions),但 没有帮助

我尝试过的。

  1. 建议参考https://sites.google.com/a/chromium.org/chromedriver/home 文章
  2. 使用 chmod 755 允许可执行权限
  3. 在 Colab 环境的不同文件夹中引用了“chromedriver.exe”,但没有成功

代码:

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

user_name = 'Username'
password = 'Password'

os.chmod('/content/chromedriver.exe', 755)
driver = webdriver.Chrome(executable_path='/content/')
driver.get("https://www.facebook.com")

element = driver.find_element_by_id("email")
element.send_keys(user_name)

element = driver.find_element_by_id("pass")
element.send_keys(password)

element.send_keys(Keys.RETURN)

driver.close()

完全错误:

---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stderr=self.log_file,
---> 76                                             stdin=PIPE)
     77         except TypeError:

4 frames
PermissionError: [Errno 13] Permission denied: '/content/'

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     86                 raise WebDriverException(
     87                     "'%s' executable may have wrong permissions. %s" % (
---> 88                         os.path.basename(self.path), self.start_error_message)
     89                 )
     90             else:

WebDriverException: Message: '' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

我的 Colab 环境快照

有人可以帮我解决这个问题吗?

PS: 相同的代码使用 Jupyter Notebook、Eclipse IDE 工作。但从长远来看,我想摆脱对 Jupyter Notebooks 的依赖并依赖基于云的 Notebook 环境,例如 Google Colab,理论上这应该让我专注于代码而不是解决库/兼容性/权限/等问题。

【问题讨论】:

  • 你用-r递归chmod了吗?

标签: python selenium google-chrome selenium-chromedriver google-colaboratory


【解决方案1】:

此错误消息...

PermissionError: [Errno 13] Permission denied: '/content/'
.
WebDriverException: Message: '' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

...表示未检测到 WebDriver 可执行文件,因此Selenium 怀疑可执行文件可能具有错误的权限。


解决方案

在传递 Key executable_path 时,您需要传递 WebDriver 变体名称的绝对路径 ,即chromedriver如下:

driver = webdriver.Chrome(executable_path='/content/chromedriver')
                          webdriver variant name ^^^chromedriver^^^ needs to be appended

参考文献

您可以在以下位置找到一些相关讨论:

【讨论】:

    猜你喜欢
    • 2017-02-12
    • 2019-11-27
    • 1970-01-01
    • 2020-10-23
    • 2019-07-31
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多