您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log

IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log

这些错误为我们提供了一些有关发生了什么错误提示,如下所示:

[Wed Mar 07 03:02:27.719608 2018] [:error] [pid 21555] [client 108.162.250.6:36139]   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
[Wed Mar 07 03:02:27.719611 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_path=log_path)

按照源代码中的 GeckoDriver 得到了两个认参数发起executable_pathlog_path=log_path如下:

    if capabilities.get("marionette"):
        capabilities.pop("marionette")
        self.service = Service(executable_path, log_path=log_path)
        self.service.start()

您的程序在这里出错,因为与 key *

[Wed Mar 07 03:02:27.719617 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
[Wed Mar 07 03:02:27.719620 2018] [:error] [pid 21555] [client 108.162.250.6:36139] IOError: [Errno 13] Permission denied: 'geckodriver.log'

根据源代码认情况下启动 GeckoDriver服务 ,如下所示:

class Service(service.Service):“”“管理GeckoDriver的启动和停止的对象。”“”

def __init__(self, executable_path, port=0, service_args=None,
             log_path="geckodriver.log", env=None):
    """Creates a new instance of the GeckoDriver remote service proxy.

    GeckoDriver provides a HTTP interface speaking the W3C WebDriver
    protocol to Marionette.

    :param log_path: Optional path for the GeckoDriver to log to.
        Defaults to _geckodriver.log_ in the current working directory.

    """
    log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None

这意味着如果您没有通过geckodriver.log程序显式传递位置,则 GeckoDriver 倾向于在 当前工作目录中 自行创建文件,并且在缺少所需 情况下,它会出错,并显示以下消息:

首要的一点是检查所使用的二进制文件间的兼容性。

一个解决方案是:

初始化 GeckoDriver 与所需的参数executable_pathlog_path有效的值(CHMOD 777geckodriver.log,如下所示:

def get_index(api_key):
if str(api_key)!=the_api_key:
return 401
base_url = 'www.google.com'
browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver", log_path="/path/to/geckodriver.log")
browser.get(base_url)
html = browser.page_source
return html

如果您打算geckodriver.logProject Workspace中 创建,请确保所需的权限(chmod 777 Project Workspace)如下:

def get_index(api_key):
if str(api_key)!=the_api_key:
return 401
base_url = 'www.google.com'
browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
browser.get(base_url)
html = browser.page_source
return html
python 2022/1/1 18:16:36 有551人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶