Skip to content

[BUG] AttributeError: 'Botright' object has no attribute '_async_class_task_store' #131

@Zorkats

Description

@Zorkats

While using botright in an automation script with playwright, I encountered the following error when trying to open a browser with botright_client.new_browser():

Traceback (most recent call last):
  File "playwright5.0.py", line 300, in <module>
    asyncio.run(download_pdfs())
  File "C:\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
  File "C:\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "C:\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete
    return future.result()
  File "playwright5.0.py", line 97, in download_pdfs
    browser = await botright_client.new_browser()
  File "C:\botright\botright.py", line 147, in new_browser
    _proxy: ProxyManager = await ProxyManager(self, proxy)
  File "C:\botright\modules\proxy_manager.py", line 45, in __ainit__
    link(self, botright)
  File "C:\botright\async_class.py", line 221, in link
    who._async_class_task_store = where.__tasks__.get_child()
  File "C:\botright\async_class.py", line 148, in __tasks__
    return self._async_class_task_store
AttributeError: 'Botright' object has no attribute '_async_class_task_store'

Steps to Reproduce:

Install dependencies with pip install botright playwright

Run the following script:
import asyncio
from botright import Botright

async def download_pdfs():
    async with Botright(headless=True) as botright_client:
        browser = await botright_client.new_browser()
        page = await browser.new_page()
        await page.goto("https://example.com")
        print(await page.title())
        await browser.close()

if __name__ == '__main__':
    asyncio.run(download_pdfs())

The error occurs when attempting to launch the browser.

Expected Behavior:

The browser should open in headless mode, navigate to the provided URL, and close without any errors.
Environment:

OS: Windows 10
Python Version: 3.11
Botright Version: 0.5.1
Playwright Version: 1.40.0
hcaptcha-challenger Version: 0.10.1.post2
Other Installed Packages:
    async-class: 0.5.0
    numpy: 1.26.4
    httpx: 0.27.2

Possible Cause:

It seems the issue is related to the initialization of the _async_class_task_store attribute in the Botright class. This attribute may not be properly initialized during the browser launch process.
Solutions Tried:

I followed the official documentation and reinstalled all dependencies in a fresh environment, but the issue persists.
Additional Comments:

This issue seems to be connected with how async_class is integrated into the flow of botright. I would appreciate any guidance on how to resolve this, or if a future update might address this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions