[Bug]: It looks like you are using Playwright Sync API inside the asyncio loop. Please use the Async API instead. #2705
Description
Version
1.48
Steps to reproduce
I am using the Spyder IDE version 5.5.1 Python 3.9.18 64 bit
My code (not mine originally can be found at --> https://screenshotone.com/blog/how-to-take-website-screenshots-in-python/#playwright-in-python) is as follows:
from playwright.sync_api import sync_playwright
def run(playwright):
# launch the browser
browser = playwright.chromium.launch()
# opens a new browser page
page = browser.new_page()
# navigate to the website
page.goto('https://www.511mt.net/#zoom=7.0841341315419255&lon=-107.10223784975705&lat=47.76128392814593&events&road-cond&rwis')
# take a full-page screenshot
page.screenshot(path='example.png', full_page=True)
# always close the browser
browser.close()
with sync_playwright() as playwright:
run(playwright)
Expected behavior
I did not expect to get the error show. I expected a screenshot to show up in my folder with the name 'example.png'
Actual behavior
Traceback (most recent call last):
File ~\anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File f:\mx_share\python\ytdownload\untitled1.py:23
with sync_playwright() as playwright:
File ~\anaconda3\lib\site-packages\playwright\sync_api_context_manager.py:47 in enter
raise Error(
Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.
Additional context
I see others have had this issue in Jupyter Notebook. I saw one use recommending the following:
playwright install-deps
I tried that as well with the same results. Not really sure how to proceed.
Environment
- Operating System: [Windows 10 Pro ver 10.0.19045]
- CPU: [Dual X5675 @3.07GHz]
- Browser: [Chrome]
- Python Version: [3.9.18]
- Other info: [144 GB RAM]