I am trying to host a headless web crawling service on railway.app which uses nixpacks to build and deploy the project. Running the project locally, everything runs smoothly and I can successfully create a headless chromedriver instance. However, when I try to deploy it on railway I get an error when trying to instantiate the driver. I have tried following this answer and install the necessary libraries but I still receive the below error:
Traceback
INFO:root:Creating driver
INFO:undetected_chromedriver.patcher:patching driver executable /root/.local/share/undetected_chromedriver/undetected_chromedriver
Traceback (most recent call last):
File "src/main.py", line 71, in <module>
initial_fetch(db)
File "src/main.py", line 27, in initial_fetch
driver = create_driver()
File "/app/src/utils/driver.py", line 10, in create_driver
driver = uc.Chrome(headless=True)
File "/opt/venv/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 429, in __init__
browser = subprocess.Popen(
File "/root/.nix-profile/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/root/.nix-profile/lib/python3.8/subprocess.py", line 1585, in _execute_child
and os.path.dirname(executable)
File "/root/.nix-profile/lib/python3.8/posixpath.py", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
nixpacks.toml
# nixpacks.toml
[phases.setup]
nixPkgs = ["...", "chromedriver"]
aptPkgs = ["...", "libglib2.0-0", "libnss3", "libgconf-2-4", "libfontconfig1"]
[start]
cmd = 'python src/main.py'
Driver.py
import logging
import undetected_chromedriver as uc
def create_driver():
logging.getLogger().setLevel(logging.INFO)
logging.info("Creating driver")
driver = uc.Chrome(headless=True)
logging.info("Driver successfully created")
return driver