NotImplementedError (asyncio, playwright)

I will need help. Thanks.

NotImplementedError
Traceback:
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 584, in _run_script
exec(code, module.dict)
File “C:\Users\user\Desktop\AI\Module 4\sentimentE.py”, line 163, in
sentiment.run()
File “C:\Users\user\Desktop\AI\Module 4\sentimentE.py”, line 130, in run
docs = loader.load()
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\langchain_core\document_loaders\base.py”, line 29, in load
return list(self.lazy_load())
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\langchain_community\document_loaders\chromium.py”, line 78, in lazy_load
html_content = asyncio.run(self.ascrape_playwright(url))
File “d:\Users\user\anaconda3\envs\tbot\lib\asyncio\runners.py”, line 44, in run
return loop.run_until_complete(main)
File “d:\Users\user\anaconda3\envs\tbot\lib\asyncio\base_events.py”, line 647, in run_until_complete
return future.result()
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\langchain_community\document_loaders\chromium.py”, line 54, in ascrape_playwright
async with async_playwright() as p:
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\playwright\async_api_context_manager.py”, line 46, in aenter
playwright = AsyncPlaywright(next(iter(done)).result())
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\playwright_impl_connection.py”, line 247, in run
await self._transport.connect()
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\playwright_impl_transport.py”, line 132, in connect
raise exc
File “d:\Users\user\anaconda3\envs\tbot\lib\site-packages\playwright_impl_transport.py”, line 120, in connect
self._proc = await asyncio.create_subprocess_exec(
File “d:\Users\user\anaconda3\envs\tbot\lib\asyncio\subprocess.py”, line 236, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
File “d:\Users\user\anaconda3\envs\tbot\lib\asyncio\base_events.py”, line 1676, in subprocess_exec
transport = await self._make_subprocess_transport(
File “d:\Users\user\anaconda3\envs\tbot\lib\asyncio\base_events.py”, line 498, in _make_subprocess_transport
raise NotImplementedError

Welcome to the community, @Hrvoje_Galic! It’s great to have you with us! :hugs:

Have you checked that you’re using versions of asyncio and playwright that are compatible with each other?

Also, are you experiencing this issue locally, on Community Cloud, or in another deployed environment?

Thanks,
Charly

Thank you for answer. I’m experiencing this issue locally.

How to check if the versions asyncio and playwright are compatible ?

Best regards

Hey @Hrvoje_Galic

In order to check if the versions of asyncio and playwright are compatible, you can do the following:

  1. Check installed versions using pip show asyncio and pip show playwright in your terminal.
  2. Review compatibility details in the official docs for Python’s asyncio and Playwright.
  3. Look for any known compatibility issues on forums or GitHub.
  4. Update Playwright if necessary with pip install --upgrade playwright.

I hope that helps.

Thanks,
Charly

Hello, I had trouble running the script in the same direction.

I need to run an asynchronous automation, but only if the user clicks a button (in a simple way).

Versions:
asyncio → 3.4.3
playwright → 1.43.0
streamlit → 1.33.0

An example of the problem I’m facing :worried::

import streamlit as st
from playwright.async_api import async_playwright
import asyncio

async def run_automation():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        page = await browser.new_page()
        await page.goto('https://docs.streamlit.io/')
        title = await page.title()
        await browser.close()
    return title

def run_async_function():
    return asyncio.run(run_automation())

if __name__ == "__main__":
    if st.button('Run Automation'):
        result_placeholder = st.empty()
        result_placeholder.text("Running automation...")
        result = run_async_function()
        result_placeholder.text(result)

Error:


NotImplementedError
Traceback:
File "C:\Users\Gabriel\anaconda3\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 584, in _run_script
    exec(code, module.__dict__)
File "C:\Users\Gabriel\OneDrive\Documentos\GitHub\dash_streamlit\teste.py", line 21, in <module>
    result = run_async_function()
             ^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\OneDrive\Documentos\GitHub\dash_streamlit\teste.py", line 15, in run_async_function
    return asyncio.run(run_automation())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\OneDrive\Documentos\GitHub\dash_streamlit\teste.py", line 6, in run_automation
    async with async_playwright() as p:
File "C:\Users\Gabriel\anaconda3\Lib\site-packages\playwright\async_api\_context_manager.py", line 46, in __aenter__
    playwright = AsyncPlaywright(next(iter(done)).result())
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\site-packages\playwright\_impl\_transport.py", line 120, in connect
    self._proc = await asyncio.create_subprocess_exec(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\subprocess.py", line 221, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\base_events.py", line 1694, in subprocess_exec
    transport = await self._make_subprocess_transport(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gabriel\anaconda3\Lib\asyncio\base_events.py", line 502, in _make_subprocess_transport
    raise NotImplementedError

Hi @gabrieldagostim! Welcome to the community! :hugs:

Out of curiosity, have you considered switching to the synchronous version of Playwright? This can help avoid using asyncio and simplify subprocess handling.

Thanks,
Charly

Hi Charlie,

Thanks for your suggestion! While I haven’t explored the synchronous version of Playwright yet, I’ll definitely look into it further to see if it’s a good fit for my needs.

I managed to get around the error by using the Selenium library (I’m not very used to it, but with your tip I will certainly switch to synchronous).

However, in this case it is just an example where I run a streamlit dash. The aim is to provide a frontent for users to do webscrapping using my computer as a host.

It sounds like a pretty cool project you have here! Glad to hear that you managed to work around things the way you wanted!

Happy Streamlit-ing!

Best,
Charly

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.