Python Selenium Geckodriver 自动安装:获取 Firefox 版本时权限被拒绝

问题描述 投票:0回答:0

我运行的 python 脚本在几个不同的发行版上运行良好,但在 Gentoo 上给我带来了麻烦。问题命令是

geckodriver_autoinstaller.install()
:

Traceback (most recent call last):
  File "/home/james/Gits/News_Scraper/main.py", line 5, in <module>
    from main_functions import *
  File "/home/james/Gits/News_Scraper/main_functions.py", line 25, in <module>
    from scraping_functions import *
  File "/home/james/Gits/News_Scraper/scraping_functions.py", line 19, in <module>
    geckodriver_autoinstaller.install()
  File "/home/james/Venvs/scraper_venv/lib/python3.10/site-packages/geckodriver_autoinstaller/__init__.py", line 15, in install
    geckodriver_filepath = utils.download_geckodriver(cwd)
  File "/home/james/Venvs/scraper_venv/lib/python3.10/site-packages/geckodriver_autoinstaller/utils.py", line 148, in download_geckodriver
    firefox_version = get_firefox_version()
  File "/home/james/Venvs/scraper_venv/lib/python3.10/site-packages/geckodriver_autoinstaller/utils.py", line 88, in get_firefox_version
    with subprocess.Popen(['firefox', '--version'], stdout=subprocess.PIPE) as proc:
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'firefox'

使用我运行的回溯:

>>> subprocess.Popen(['firefox', '--version'], stdout=subprocess.PIPE)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'firefox'

我检查了 shell 中的 firefox 命令,得到了权限被拒绝的错误。在我的系统中,firefox 被称为

firefox-bin
,所以我明白为什么它不起作用,但我本以为错误是“找不到命令”而不是“权限被拒绝”。我假设这与我从 Python 中获得的“权限被拒绝”相同。

~$ which firefox
firefox not found

~$ which firefox-bin
/usr/bin/firefox-bin


I thought that maybe I could just alias `firefox-bin` to `firefox` but no luck:

~$哪个firefox
firefox:别名为 firefox-bin

>>> import subprocess
>>> subprocess.Popen(['firefox', '--version'], stdout=subprocess.PIPE)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'firefox'
>>> 

我是否误以为 Python 中显示的“权限被拒绝”错误是由于 firefox 可执行文件的名称为 firefox=bin?或者在 shell 中设置别名可能还不够?

python selenium-webdriver permissions alias geckodriver
© www.soinside.com 2019 - 2024. All rights reserved.