Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Error when firefox app does not exist on Mac #9

@jackieshu16

Description

@jackieshu16

Error seen:

    geckodriver_autoinstaller.install()
/usr/local/lib/python3.9/site-packages/geckodriver_autoinstaller/__init__.py:15: in install
    geckodriver_filepath = utils.download_geckodriver(cwd)
/usr/local/lib/python3.9/site-packages/geckodriver_autoinstaller/utils.py:148: in download_geckodriver
    firefox_version = get_firefox_version()
/usr/local/lib/python3.9/site-packages/geckodriver_autoinstaller/utils.py:91: in get_firefox_version
    process = subprocess.Popen(['/Applications/Firefox.app/Contents/MacOS/firefox', '--version'], stdout=subprocess.PIPE)
/usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py:951: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
/usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py:1823: in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
E   FileNotFoundError: [Errno 2] No such file or directory: '/Applications/Firefox.app/Contents/MacOS/firefox'

I made a tiny change, so it won't error out.

--- a/geckodriver_autoinstaller/utils.py
+++ b/geckodriver_autoinstaller/utils.py
@@ -95,8 +95,12 @@ def get_firefox_version():
         with subprocess.Popen(['firefox', '--version'], stdout=subprocess.PIPE) as proc:
             version = proc.stdout.read().decode('utf-8').replace('Mozilla Firefox', '').strip()
     elif platform == 'mac':
-        process = subprocess.Popen(['/Applications/Firefox.app/Contents/MacOS/firefox', '--version'], stdout=subprocess.PIPE)
-        version = process.communicate()[0].decode('UTF-8').replace('Mozilla Firefox', '').strip()
+        ff_path = '/Applications/Firefox.app/Contents/MacOS/firefox'
+        if os.path.exists(ff_path):
+            process = subprocess.Popen([ff_path, '--version'], stdout=subprocess.PIPE)
+            version = process.communicate()[0].decode('UTF-8').replace('Mozilla Firefox', '').strip()
+        else:
+            return
     elif platform == 'win':
         path1 = 'C:\\PROGRA~1\\Mozilla Firefox\\firefox.exe'
         path2 = 'C:\\PROGRA~2\\Mozilla Firefox\\firefox.exe'

Please take a look. Thank you. @yeongbin-jo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions