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

Error when firefox app does not exist on Mac #9

Open
jackieshu16 opened this issue Mar 31, 2021 · 0 comments
Open

Error when firefox app does not exist on Mac #9

jackieshu16 opened this issue Mar 31, 2021 · 0 comments

Comments

@jackieshu16
Copy link

jackieshu16 commented Mar 31, 2021

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/[email protected]/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/[email protected]/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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant