eggplants / deepl-cli

DeepL Translator CLI (without API Key)
https://pypi.org/project/deepl-cli/
MIT License
254 stars 17 forks source link

playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed #221

Open noembryo opened 6 months ago

noembryo commented 6 months ago

Up until a couple of days ago, I was using v.0.5.2 and everything was OK. The limit for the DeepL to block my IP was ~400.000 characters. From yesterday on, it seems that this limit went down to ~20.000/30.000 characters..

So, I tried to update deepl-cli thinking that you might have a fix for this, but I encounter another problem. After installing deepl-cli v.0.6.0, and updated playwright library to the latest version (v.1.41.2), I get this error:: playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed.

Since I don't see anyone mention anything about it, I have to ask for ideas..

Full traceback:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<Base.start_translating() done, defined at D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py:588> exception=TargetClosedError('Target page, context or browser has been closed')>
Traceback (most recent call last):
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 613, in start_translating
    await asyncio.gather(*translators)
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 625, in translator
    trans_text = await self.translate(chunk)
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 667, in translate
    return await t.translate_async(text)
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\deepl\deepl.py", line 121, in __translate
    await page.goto(f"{url}#{self.fr_lang}/{self.to_lang}/{script}")
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\async_api\_generated.py", line 9275, in goto
    await self._impl_obj.goto(
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_page.py", line 484, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_frame.py", line 149, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 63, in send
    return await self._connection.wrap_api_call(
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 495, in wrap_api_call
    return await cb()
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 101, in inner_send
    result = next(iter(done)).result()
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed
Wotamin commented 5 months ago

Nothing much to add, I have the same issue. Ran on local W11 env.

File "c:\Program Files\Python311\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Program Files\Python311\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\test_deepl.py", line 4, in <module>
    deepl.translate("hello") #=> "こんにちわ"
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\deepl.py", line 86, in translate
    return loop.run_until_complete(self.__translate(script))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\deepl.py", line 122, in __translate
    await page.goto(f"{url}#{self.fr_lang}/{self.to_lang}/{script}")
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\async_api\_generated.py", line 9275, in goto
    await self._impl_obj.goto(
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_page.py", line 484, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_frame.py", line 149, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 63, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 495, in wrap_api_call
    return await cb()
           ^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 101, in inner_send
    result = next(iter(done)).result()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed
Rokandor commented 4 months ago

I am also facing this issue Error:Target page, context or browser has been closed And it happens randomly as well without more details

eggplants commented 4 months ago

Latest test fails only on Windows. I don't have a Wnidows environment, can anyone debug this? https://github.com/eggplants/deepl-cli/actions/runs/8888722014