Pyppeteer在20秒后通过pyppeteer.errors.NetworkError崩溃 [英] Pyppeteer crushes after 20 seconds with pyppeteer.errors.NetworkError
问题描述
在使用 pyppeteer 来控制Chromium的过程中,大约20秒后我收到了一个错误工作:
pyppeteer.errors.NetworkError:协议错误(Runtime.callFunctionOn):会话关闭.该页面很可能已关闭.
如此处所述所述,问题可能是由python 的实现引起的websockets> = 7
软件包及其在pyppeteer中的用法.
有3种防止与Chromium断开连接的解决方案:
-修补类似此处所述的代码(首选):
在运行任何其他Pyppeteer命令之前运行该代码段
def patch_pyppeteer():导入pyppeteer.connectionoriginal_method = pyppeteer.connection.websockets.client.connectdef new_method(* args,** kwargs):kwargs ['ping_interval'] =无kwargs ['ping_timeout'] =无返回original_method(* args,** kwargs)pyppeteer.connection.websockets.client.connect = new_methodpatch_pyppeteer()
-更改麻烦的库 :
将 websockets
包降级为 websockets-6.0
,例如通过 pip3 install websockets == 6.0 --force-reinstall
(在您的虚拟环境中)
-更改代码库如 pull请求中所述,有望很快合并.>
During usage of pyppeteer for controlling the Chromium I have been receiving an error approximately after 20 seconds of work:
pyppeteer.errors.NetworkError: Protocol Error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
As described here the issue is probably caused by implementation of python websockets>=7
package and by its usage within pyppeteer.
There are 3 solutions to prevent disconnection from Chromium:
- Patching the code like described here (preferable):
Run the snippet before running any other Pyppeteer commands
def patch_pyppeteer():
import pyppeteer.connection
original_method = pyppeteer.connection.websockets.client.connect
def new_method(*args, **kwargs):
kwargs['ping_interval'] = None
kwargs['ping_timeout'] = None
return original_method(*args, **kwargs)
pyppeteer.connection.websockets.client.connect = new_method
patch_pyppeteer()
- Change the trouble making library:
Downgrade websockets
package to websockets-6.0
e.g via
pip3 install websockets==6.0 --force-reinstall
(in your virtual environment)
- Change the code base as described in this pull request, which will be hopefully merged soon.
这篇关于Pyppeteer在20秒后通过pyppeteer.errors.NetworkError崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!