1

I have a web scraper that uses Undetected Chromedriver & WebDriverManager to download & automate a Chromium webdriver.

On Windows I initialize the Undetcted Chromedriver instance by passing the executable_path to the output of ChromeDriverManager().install(). This works fine.

Now I am trying to Dockerize my application, however I am getting:

Error: expected str, bytes or os.PathLike object, not NoneType

when trying to initialize my object as lined out below. I'm not getting any other context to where the error is being raised from.

Driver initialisation

options = uc.ChromeOptions()
path = ChromeDriverManager(os_type="linux64").install()
driver = uc.Chrome(
    options=options, executable_path=path, force=True
)

I've also tried:

  1. Check if the file at the path ChromeDriverManager.install() returns exists using os.path.isfile() which returned True
  2. Pass a relative path to executable_path.
victorbrnk
  • 11
  • 4
  • It could be that `executable_path` is deprecated in new versions. Use `webdriver.Chrome(service=Service(chromedriver_path), options=options)` and add this import `from selenium.webdriver.chrome.service import Service`. – sound wave Jan 20 '23 at 14:28
  • Thanks for the swift reply @soundwave but this raises the same exception. – victorbrnk Jan 20 '23 at 14:35
  • Can you provide a backtrace? – kaliiiiiiiii Jan 20 '23 at 17:21
  • @kaliiiiiiiii the exception isn't giving one and I can't get it from `exception.__traceback__` object either. – victorbrnk Jan 23 '23 at 08:01
  • did you try using `import traceback` `traceback.print_exc` inside a catch statement? – kaliiiiiiiii Jan 23 '23 at 11:10
  • @kaliiiiiiiii I've tried `traceback.print_exc()` inside the catch statement, and I've tried to raise the exception using the `_with_traceback(exception.__traceback__)` and I don't get an actual stack trace, only the error message. – victorbrnk Jan 23 '23 at 12:20
  • Hmm well that's weird. Meybe its inside some thread, multiprocess or subprocess. or the exception is only printed – kaliiiiiiiii Jan 23 '23 at 13:18

1 Answers1

0

I don't quite know where it went wrong on my first Docker container but here's how I fixed it:

It seems like the ChromeDriver wasn't being downloaded properly. I'm guessing something to do with $_PATH variables.

I installed the Chromedriver through docker by adding this to the Dockerfile

RUN wget -q "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
RUN apt install -y ./google-chrome-stable_current_amd64.deb

RUN wget -q "https://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip" -O /tmp/chromedriver.zip \
    && unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ \
    && rm /tmp/chromedriver.zip \
    && chmod +x /usr/local/bin/chromedriver

Which works great

victorbrnk
  • 11
  • 4