admin管理员组文章数量:1293311
I am trying to deploy a FastAPI application with Selenium WebDriver on Vercel. The application works fine locally, but when deployed to Vercel, I encounter a read-only file system error related to the Selenium WebDriver cache folder.
Error Message:
WARNING:selenium.webdrivermon.selenium_manager:Cache folder (/home/sbx_user1051/.cache/selenium) cannot be created: Read-only file system (os error 30)
127.0.0.1 - - [12/Feb/2025 21:42:10] "GET /api/search?q=laptop HTTP/1.1" 500 -
Code Snippets:
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdrivermon.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from seleniummon.exceptions import TimeoutException, WebDriverException, NoSuchElementException
from bs4 import BeautifulSoup
from time import sleep
import urllib.parse
import re
import os
class StoreScraper:
def __init__(self, store_name):
self.store_name = store_name
self.driver = self.setup_driver()
def setup_driver(self):
options = EdgeOptions()
# Headless mode for performance
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--disable-popup-blocking")
# Use a custom user-agent to avoid detection
options.add_argument(
"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/109.0.0.0 Safari/537.36"
)
# Use the /tmp directory for WebDriver cache and user data
temp_dir = "/tmp/webdriver"
os.makedirs(temp_dir, exist_ok=True)
options.add_argument(f"--user-data-dir={temp_dir}")
options.add_argument(f"--disk-cache-dir={temp_dir}")
# Initialize Edge WebDriver (Ensure `msedgedriver` is in PATH)
service = EdgeService()
driver = webdriver.Edge(service=service, options=options)
return driver
def quit_driver(self):
if self.driver:
self.driver.quit()
self.driver = None
# Other methods...
What I've Tried:
- Using a temporary directory for the WebDriver cache.
- Setting the cache directory to a temporary directory.
How can I resolve the read-only file system error related to the Selenium WebDriver cache folder when deploying my FastAPI application on Vercel?
本文标签: pythonFastAPISelenium WebDriver on Vercel Cache Folder ReadOnly File System ErrorStack Overflow
版权声明:本文标题:python - FastAPI + Selenium WebDriver on Vercel: Cache Folder Read-Only File System Error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741573724a2386159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论