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

Doesnt work with poetry (but with miniconda) #2029

Open
Raidus opened this issue Sep 24, 2024 · 0 comments
Open

Doesnt work with poetry (but with miniconda) #2029

Raidus opened this issue Sep 24, 2024 · 0 comments

Comments

@Raidus
Copy link

Raidus commented Sep 24, 2024

I am running a simple script

#!/usr/bin/env python3

import logging

logging.basicConfig(level=logging.INFO)

import nodriver as uc


async def main():
    # Start the nodriver
    driver = await uc.start(
        headless=False,
        sandbox=False,
        browser_executable_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    )

    # Navigate to the Instagram account
    instagram_account_url = (
        "https://www.instagram.com/therock"
    )
    print(f"Navigating to {instagram_account_url}")
    tab = await driver.get(instagram_account_url)

    # Wait for the page to load completely
    await tab.sleep(5)  # Adjust the sleep time if necessary

    # Take a screenshot and save it locally
    screenshot_filename = "instagram_screenshot.png"
    print(f"Taking screenshot and saving as {screenshot_filename}")
    await tab.screenshot(screenshot_filename)

    # Close the browser
    driver.stop()
    print("Browser closed")


if __name__ == "__main__":
    # Run the asynchronous main function
    uc.loop().run_until_complete(main())

It works perfectly when using miniconda but using poetry it breakes when I run
poetry run scripts/social/account_screenshot.py

poetry run scripts/social/account_screenshot.py
INFO:nodriver.core.browser:starting
        executable :/Applications/Google Chrome.app/Contents/MacOS/Google Chrome

arguments:
--remote-allow-origins=*
        --no-first-run
        --no-service-autorun
        --no-default-browser-check
        --homepage=about:blank
        --no-pings
        --password-store=basic
        --disable-infobars
        --disable-breakpad
        --disable-component-update
        --disable-backgrounding-occluded-windows
        --disable-renderer-backgrounding
        --disable-background-networking
        --disable-dev-shm-usage
        --disable-features=IsolateOrigins,site-per-process
        --disable-session-crashed-bubble
        --disable-search-engine-choice-screen
        --user-data-dir=/var/folders/k2/7321ff_s2rv1cphl835x1trh0000gn/T/uc_bvxes8sj
        --disable-features=IsolateOrigins,site-per-process
        --disable-session-crashed-bubble
        --no-sandbox
        --remote-debugging-host=127.0.0.1
        --remote-debugging-port=64616
Traceback (most recent call last):
  File "/Users/me
/Coding/Projects/github/crawlers/scripts/social/account_screenshot.py", line 49, in <module>
    uc.loop().run_until_complete(main())
  File "/usr/local/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/me
/Coding/Projects/github/crawlers/scripts/social/account_screenshot.py", line 12, in main
    driver = await uc.start(
             ^^^^^^^^^^^^^^^
  File "/Users/me
/Library/Caches/pypoetry/virtualenvs/crawlers-pbtkaTlW-py3.12/lib/python3.12/site-packages/nodriver/core/util.py", line 96, in start
    return await Browser.create(config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me
/Library/Caches/pypoetry/virtualenvs/crawlers-pbtkaTlW-py3.12/lib/python3.12/site-packages/nodriver/core/browser.py", line 91, in create
    await instance.start()
  File "/Users/me
/Library/Caches/pypoetry/virtualenvs/crawlers-pbtkaTlW-py3.12/lib/python3.12/site-packages/nodriver/core/browser.py", line 352, in start
    raise Exception(
Exception: 
                ---------------------
                Failed to connect to browser
                ---------------------
                One of the causes could be when you are running as root.
                In that case you need to pass no_sandbox=True 
                
Exception ignored in atexit callback: <function deconstruct_browser at 0x10d6c8860>
Traceback (most recent call last):
  File "/Users/me
/Library/Caches/pypoetry/virtualenvs/crawlers-pbtkaTlW-py3.12/lib/python3.12/site-packages/nodriver/core/util.py", line 146, in deconstruct_browser
    _.stop()
  File "/Users/me
/Library/Caches/pypoetry/virtualenvs/crawlers-pbtkaTlW-py3.12/lib/python3.12/site-packages/nodriver/core/browser.py", line 558, in stop
    asyncio.get_event_loop().create_task(self.connection.aclose())
                                         ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'aclose'

Does someone has an idea to fix this? The browser is opening but looks like the script can't connect to it.

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

1 participant