You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a Simple FastAPI App:
Create a FastAPI application that allows you to take screenshots of any web page
Use Synchronous or Asynchronous Methods:
You can use either synchronous or asynchronous approaches for your application
Run the Application with reload=True:
Start the FastAPI app with reload=True enabled, like this:
uvicorn.run("playwriteTest:app", host="0.0.0.0", port=8000, reload=True)
You will start encountring the error
Im attaching my code
fromfastapiimportFastAPI, HTTPExceptionfromplaywright.async_apiimportasync_playwrightimportuuidimportosimportuvicornapp=FastAPI()
asyncdeftakeScreenshot(url, screenshot_path):
asyncwithasync_playwright() asplaywright:
browser=awaitplaywright.chromium.launch(headless=True)
context=awaitbrowser.new_context(ignore_https_errors=True)
page=awaitcontext.new_page()
# Go to the target URLawaitpage.goto(url, timeout=60000) # 60 seconds timeout# Wait for the page to load fullyawaitpage.wait_for_load_state("networkidle")
# Capture and save the screenshotawaitpage.screenshot(path=screenshot_path, full_page=True)
# Close the browserawaitbrowser.close()
# Define a directory for storing screenshotsSCREENSHOT_DIR="screenshots"os.makedirs(SCREENSHOT_DIR, exist_ok=True)
@app.post("/screenshot/")asyncdeftake_screenshot():
screenshot_path=os.path.join(SCREENSHOT_DIR, f"{uuid.uuid4()}.png")
url='https://pypi.org/project/playwright/'try:
awaittakeScreenshot(url, screenshot_path)
exceptExceptionase:
raiseHTTPException(
status_code=500, detail=f"Error capturing screenshot: {str(e)}"
)
return {"screenshot_path": screenshot_path, "message": "Screenshot taken successfully!"}
if__name__=="__main__":
# if you use this you will encounter the erroruvicorn.run("playwriteTest:app", host="0.0.0.0", port=8000, reload=True)
# uncomment this it will start work #uvicorn.run("playwriteTest:app", host="0.0.0.0", port=8000, reload=False)
Expected behavior
When running with reload=True, you may encounter the error
raise NotImplementedError
Fix the Issue by Setting reload=False:
To resolve this error, update the reload parameter to False.
Actual behavior
Run the Application with reload=True:
Start the FastAPI app with reload=True enabled, like this:
uvicorn.run("playwriteTest:app", host="0.0.0.0", port=8000, reload=True)
When running with reload=True, you may encounter the error
raise NotImplementedError
Additional context
Dear Team,
Many of us are encountering this issue, and we would greatly appreciate it if you could look into it. This is a fantastic package that we truly enjoy using, and we hope the issue can be addressed promptly. I've attached my code for your reference.
We noticed that the issue becomes apparent when running Uvicorn with the reload parameter set to True. If we set the reload parameter to False, the error does not occur. We hope this issue will be resolved in the next release.
Thank you for your attention to this matter!
Environment
currently im using windows
- my system configuration
Host Name: AC-LAP-081
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19045 N/A Build 19045
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: User
Registered Organization:
Product ID: 00330-54179-04263-AAOEM
Original Install Date: 29-12-2022, 01:33:44
System Boot Time: 27-12-2024, 04:25:30
System Manufacturer: LENOVO
System Model: 20VD
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 140 Stepping 1 GenuineIntel ~2803 Mhz
BIOS Version: LENOVO F8CN46WW(V2.09), 24-12-2021
The text was updated successfully, but these errors were encountered:
Version
1.49.1
Steps to reproduce
Expected behavior
Actual behavior
Additional context
Dear Team,
Many of us are encountering this issue, and we would greatly appreciate it if you could look into it. This is a fantastic package that we truly enjoy using, and we hope the issue can be addressed promptly. I've attached my code for your reference.
We noticed that the issue becomes apparent when running Uvicorn with the reload parameter set to True. If we set the reload parameter to False, the error does not occur. We hope this issue will be resolved in the next release.
Thank you for your attention to this matter!
Environment
The text was updated successfully, but these errors were encountered: