-
First Check
Commit to Help
Example Code// api.py
from playwright.async_api import async_playwright
class FS131VIAPI:
def __init__(self):
self.cookie = None
async def fetch(self, params):
await self.login_for_cookie()
logger.info(params)
async def login_for_cookie(self):
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context()
page = await context.new_page()
await page.goto("https://cn.bing.com/")
print(await page.title())
print(await context.cookies())
self.cookie = await context.cookies()
await context.close()
// main.py
...
from api import FS131VIAPI
fs131vi_api = FS131VIAPI()
@app.post("/")
async def index():
await fs131vi_api.fetch({"SERVICE_IDS": "xxx"}) Descriptionopen the browser and call the endpoint '/' Operating SystemWindows Operating System Detailswindows 10 FastAPI Version0.85.0 Python Version3.10.2 Additional Context |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
It works fine. I am not able to find any issues. Below is the code I used. import fastapi
from playwright.async_api import async_playwright
class FS131VIAPI:
def __init__(self):
self.cookie = None
async def fetch(self, params):
await self.login_for_cookie()
async def login_for_cookie(self):
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context()
page = await context.new_page()
await page.goto("https://cn.bing.com/")
print(await page.title())
print(await context.cookies())
self.cookie = await context.cookies()
await context.close()
fs131vi_api = FS131VIAPI()
app = fastapi.FastAPI()
@app.get("/")
async def index():
await fs131vi_api.fetch({"SERVICE_IDS": "xxx"}) |
Beta Was this translation helpful? Give feedback.
-
In order to be able to find your issue more easily could you please replace "NotEmplementedError" with "NotImplementedError" |
Beta Was this translation helpful? Give feedback.
-
i am running on windows 10, with python 3.10.2, playwright-python 1.26.1, fastapi 0.85.0, which version did you use? |
Beta Was this translation helpful? Give feedback.
-
I get the same NotImplementedError Error using fastapi and playwright. the playwright function is valid just after removing out of the fastapi api wrapper, i.e. remove "@app.get("/test")" code attached below:
|
Beta Was this translation helpful? Give feedback.
-
problem can be solved by setting reload=False.
|
Beta Was this translation helpful? Give feedback.
-
i am talking about playwright-python work with reload when developing |
Beta Was this translation helpful? Give feedback.
-
@phoenixor did you solve this? |
Beta Was this translation helpful? Give feedback.
-
This problem still exists in 2024 |
Beta Was this translation helpful? Give feedback.
It works fine. I am not able to find any issues. Below is the code I used.