Streamlit App Deployment Error: WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

71 views Asked by At

I have deployed a streamlit web app which has web scraping features implemented to an Azure Web App instance, yet I am getting this error when the web page loads:

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

I have found in other replies that some packages may need to be installed (chromium-browser, seleniumbase), but when I add them to requirements.txt, the deployment fails entirely.

1

There are 1 answers

0
Dasari Kamali On

I used the code below for web scraping with Streamlit using the Selenium web driver, and it was successfully deployed to the Azure App Service.

Code :

import streamlit as st
from selenium import webdriver

def scrape_title(url):
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')  
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(options=options)  
    driver.get(url)  
    title = driver.title  
    driver.quit()  
    return title

st.title("Chrome Web Scraping with Selenium")

url = st.text_input("Enter URL:")
if st.button("Scrape"):
    if url:
        st.write("Scraping title from:", url)
        title = scrape_title(url)
        st.write("Title:", title)
    else:
        st.write("Please enter a URL.")

Output :

The following code ran successfully. I received the Streamlit output in the browser, where you can enter your desired URL. For example, I entered a flowers website URL as shown below.

enter image description here

Upon clicking the Scraping title above, I was directed to the flowers website.

enter image description here

In the Azure Web App, I added the below startup command in Configuration > General settings > Startup Command.

python -m streamlit run <yourfilename.py> --server.port 8000 --server.address 0.0.0.0

enter image description here

Azure Web app output :

I entered a cars website URL as shown below.

enter image description here

enter image description here