pyppeteer error: No session with given id

79 Views Asked by At

My script seems to be working fine, up until it doesn't anymore and throws this error. I have no idea why:

Future exception was never retrieved
future: <Future finished exception=NetworkError('Protocol error (Target.detachFromTarget): No session with given id')>
pyppeteer.errors.NetworkError: Protocol error (Target.detachFromTarget): No session with given id

Here is a simplified version of what I do:

import nest_asyncio
nest_asyncio.apply()
import asyncio, time, datetime
from pyppeteer import launch

async def main():

    options_dict = {'ignoreDefaultArgs': [ '--enable-automation']}    
    browser = await launch(options_dict, headless=False)
    page = await browser.newPage()
    await page.goto(url)
    await page.waitForSelector('input[autocomplete=username]')
    await page.click('[role=button]')
    while True:
        await page.goto(url)
        target_url = 'UserData'
        
        await asyncio.sleep(5)
        res = await page.waitForResponse(lambda req: target_url in req.url)
        res_json = await res.json()
        # other stuff not related to asyncio/pyppeteer so not relevant I think
        print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        time.sleep(600)

asyncio.get_event_loop().run_until_complete(main())

Any idea on what is causing the issue?

Notable point (maybe): the error message doesn't interrupt the while True loop or the script, it just gets printed alongside the print statement at every loop cycle.

0

There are 0 best solutions below