Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Path for Driver (Question) #951

Closed
ottogutierrez opened this issue Dec 14, 2022 · 2 comments
Closed

Download Path for Driver (Question) #951

ottogutierrez opened this issue Dec 14, 2022 · 2 comments

Comments

@ottogutierrez
Copy link

ottogutierrez commented Dec 14, 2022

Hello, I'm currently trying to use undetected_chromedriver in AWS as a lambda function.

So far, I have created the layer with the "undetected_chromedriver" library included. However, as I understand, the library automatically downloads the correct driver according to the machine. Since it is running in an AWS lambda function, it appears that only the '/tmp/' folder is available (Linux based system).

Is there a way to modify the download folder for the chromedriver?

This is the error I encounter

Traceback (most recent call last):
File "/opt/python/lib/python3.7/site-packages/undetected_chromedriver/patcher.py", line 252, in __del__
if self._custom_exe_path:
AttributeError: 'Patcher' object has no attribute '_custom_exe_path'
[ERROR] OSError: [Errno 30] Read-only file system: '/home/sbx_user1051'

Thanks!

@ottogutierrez
Copy link
Author

I think this would get resolved with #643. Thanks!

@dajiangqingzhou
Copy link

dajiangqingzhou commented Jul 4, 2023

hi @ottogutierrez ! Maybe I'm facing the same problem as you. can you give me some tips? thank you very much!
i use python3.7
selenium==3.9.1
undetect-chromedriver=3.5.0
chrome-driver==2.31
headlesschrome==v1.0.0-41

there is my code:

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


chrome_dir = '/opt/chrome'
chrome_path = chrome_dir + '/headless-chromium'
chrome_driver_path = chrome_dir + '/chromedriver'

def create_undetected_driver():
    import undetected_chromedriver as uc
    from undetected_chromedriver.options import ChromeOptions
    chrome_options = ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--single-process')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument("--disable-gpu")
    chrome_options.binary_location = chrome_path
    return uc.Chrome(driver_executable_path=chrome_driver_path,
                       headless=True,
                       options=chrome_options,
                       use_subprocess=False,
                       user_data_dir="/tmp")

def lambda_handler(event, context):
    """The actual function that will be called"""
    driver = create_undetected_driver()
    try:
        url = 'https://nowsecure.nl'
        driver.get(url)
        image = driver.get_screenshot_as_base64()
        return {
            'headers': { "Content-Type": "image/png" },
            'statusCode': 200,
            'body': image,
            'isBase64Encoded': True
        }
    finally:
        driver.quit()
    
    return {
        'statusCode': 200,
        'body': json.dumps(str(event))
    }

the error:
[ERROR] OSError: [Errno 38] Function not implemented
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 42, in lambda_handler
driver = create_undetected_driver()
File "/var/task/lambda_function.py", line 23, in create_undetected_driver
import undetected_chromedriver as uc
File "/opt/python/lib/python3.7/site-packages/undetected_chromedriver/init.py", line 43, in
from .patcher import IS_POSIX
File "/opt/python/lib/python3.7/site-packages/undetected_chromedriver/patcher.py", line 25, in
class Patcher(object):
File "/opt/python/lib/python3.7/site-packages/undetected_chromedriver/patcher.py", line 26, in Patcher
lock = Lock()
File "/var/lang/lib/python3.7/multiprocessing/context.py", line 67, in Lock
return Lock(ctx=self.get_context())
File "/var/lang/lib/python3.7/multiprocessing/synchronize.py", line 162, in init
SemLock.init(self, SEMAPHORE, 1, 1, ctx=ctx)
File "/var/lang/lib/python3.7/multiprocessing/synchronize.py", line 59, in init
unlink_now)

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants