question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot use playwright-python in fastapi, got NotImplementedError

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

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"})

Description

open the browser and call the endpoint ‘/’ fastapi received the request and call playwright-python to call “https://cn.bing.com/”, return cookies

Operating System

Windows

Operating System Details

windows 10

FastAPI Version

0.85.0

Python Version

3.10.2

Additional Context

S)@V _9AB{UFG%U)_732RNB

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
phemancommented, Nov 18, 2022

problem can be solved by setting reload=False. more can be found on https://github.com/microsoft/playwright-python/issues/1099

if __name__ == "__main__":

    uvicorn.run(
        "test:app",
        host="0.0.0.0",
        reload=False,
        port=8002
    )
0reactions
phoenixorcommented, Nov 18, 2022

problem can be solved by setting reload=False. more can be found on microsoft/playwright-python#1099

if __name__ == "__main__":

    uvicorn.run(
        "test:app",
        host="0.0.0.0",
        reload=False,
        port=8002
    )

i am talking about playwright-python work with reload when developing

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Running an Asyncio Subprocess in FastApi results in ...
I've read similar questions on the issue: Why am I getting NotImplementedError with async and await on Windows? Asyncio.create_subprocess_exec ...
Read more >
as a beginner , mine is pyinputplus : r/Python - Reddit
I barely find my self writing a class that is not attrs and usually if i do, i change my mind after 20...
Read more >
Use get_column_sets in dbt-osmosis With Examples | LambdaTest
Learn how to use get_column_sets function in dbt-osmosis framework for your next python automation project with LambdaTest Automation Testing Advisor.
Read more >
[Example code]-Google scrape returns no description or email
I'm trying to get a description and email from each of Google searches, but it returns only titles and links. I'm using Selenium...
Read more >
how to install express in console Code Example
What is Node.js, Express.js? ... is npm express? ... Which command is correct to install the express package using Node Package Manager? ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found