adieuadieu / serverless-chrome

🌐 Run headless Chrome/Chromium on AWS Lambda
MIT License
2.86k stars 280 forks source link

/opt/chromedriver unexpectedly exited. Status code was 127\n #337

Open syedshahabali93 opened 2 years ago

syedshahabali93 commented 2 years ago

I am running python script using selenium in aws lambda. I have created 2 layers 1 for selenium and 1 for chromedriver and headless-chromium. On execution I receive error

Response { "errorMessage": "Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127\n", "errorType": "WebDriverException", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 36, in lambda_handler\n driver = webdriver.Chrome(options=options, executable_path=chromedriver_path, desired_capabilities=d,)\n", " File \"/opt/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py\", line 70, in __init__\n super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], \"goog\",\n", " File \"/opt/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py\", line 89, in __init__\n self.service.start()\n", " File \"/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py\", line 98, in start\n self.assert_process_still_running()\n", " File \"/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py\", line 110, in assert_process_still_running\n raise WebDriverException(\n" ] }

I am using python version 3.8. Downloaded latest version v1.0.0-57 headless-chromium from https://github.com/adieuadieu/serverless-chrome/releases?page=1 ChromeDriver version for this chromium is https://chromedriver.storage.googleapis.com/index.html?path=86.0.4240.22/

I am using this tutorial for deploying to lambda https://dev.to/awscommunity-asean/creating-an-api-that-runs-selenium-via-aws-lambda-3ck3 This tutorial uses python3.6 but I wanted to use a newer version.

Posting my lambda function here

`from selenium import webdriver from selenium.webdriver.chrome.options import Options

def lambda_handler(event, context): print("Launching browser") options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument("--no-sandbox") options.add_argument("--log-level=1") options.add_argument("--start-maximized") options.binary_location = "/opt/headless-chromium" chromedriver_path = "/opt/chromedriver" driver = webdriver.Chrome(options=options, executable_path=chromedriver_path)

driver.get('https://www.google.com/')

driver.close();
driver.quit();

response = {
    "statusCode": 200,
    "body": "Selenium Headless Chrome Initialized"
}

return response`
warawara28 commented 2 years ago

I got same error.

Service /opt/chromedriver unexpectedly exited. Status code was: 127\n

I downgraded python version from 3.8 to 3.7 and fixed this problem.

kerl4real commented 2 years ago

I also started encountering this error when I upgraded from python 3.6 to 3.9. I did this because AWS deprecated 3.6. So I find the solution to downgrade to 3.7 troublesome, and it will only be a matter of time until 3.7 is deprecated as well.

selected-pixel-jameson commented 2 years ago

I have yet to see this successfully run using Python 3.7.x, which basically makes this repository obsolete now that Python 3.6 is not supported.