'PermissionError: Permission denied: 'geckodriver.log' when using Selenium to open Firefox

I'm working on Chapter 11 of Automate the Boring Stuff and I'm attempting to follow along with the examples that involve Selenium. I am using a MacBook Air with Python 3.9.1 64-bit, as well as Visual Studio Code for background. I've been having a lot of issues with this code:

from selenium import webdriver
browser=webdriver.Firefox()

From what I've researched, in order to execute the above code, I need to install both selenium and geckodriver. I found one site that lays out some instructions nicely: https://medium.com/dropout-analytics/selenium-and-geckodriver-on-mac-b411dbfe61bc.

According to the instructions on the above site, I went to: https://github.com/mozilla/geckodriver/releases and downloaded 'geckodriver-v0.30.0-macos.tar.gz' and 'geckodriver-v0.30.0-linux64.tar.gz' (I wasn't really sure which version was appropriate for my situation). I went back to the Terminal window and ran sudo nano /etc/paths and added both /usr/local/bin/geckodriver and /Users/myname/Downloads/geckodriver to the System PATH, following the instructions.

I then attempted the first code again and I encountered the following error message (edit: I forgot to mention that the Firefox browser didn't open as desired):

>>> from selenium import webdriver
>>> browser=webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
    self.service = Service(
  File "/opt/homebrew/lib/python3.9/site-packages/selenium/webdriver/firefox/service.py", line 50, in __init__
    log_file = open(log_path, "a+") if log_path else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'

This is where I'm really at a loss. I assume the error is telling me that 'geckodriver.log' needs to be moved to another directory that I have permissions to use it (/usr/local/bin??) but I have encountered errors when attempting to do so.

import shutil
>>> shutil.move('/Users/myname/geckodriver.log', '/usr/local/bin')
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.9.1_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/shutil.py", line 806, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/Users/atsushiidobe/geckodriver.log' -> '/usr/local/bin/geckodriver.log'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/[email protected]/3.9.1_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/shutil.py", line 820, in move
    copy_function(src, real_dst)
  File "/opt/homebrew/Cellar/[email protected]/3.9.1_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/shutil.py", line 435, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/opt/homebrew/Cellar/[email protected]/3.9.1_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/geckodriver.log'

I would really appreciate it if anyone has any suggestions on how to solve this issue. I've looked at quite a few YouTube videos and online posts about how to install geckodriver and yet I haven't managed to solve this problem.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source