当使用pyppeteer报出如下错误时pyppeteer.errors.BrowserError: Browser closed unexpectedly
问题:安装好pyppeteer,初次运行时可能会报如下错误pyppeteer.errors.BrowserError: Browser closed unexpectedly:[0924/153706.301300:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not suppo...
·
问题:
安装好pyppeteer,初次运行时可能会报如下错误
pyppeteer.errors.BrowserError: Browser closed unexpectedly:
[0924/153706.301300:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180
原因:
pyppeteer需要在没有沙盒arg的情况下运行
解决办法:
在middlewares.py中找到我们自定义的middlewares,并找到getbrowser方法,将self.browser = await pyppeteer.launch()改为self.browser = await pyppeteer.launch(options={'args': ['--no-sandbox']}) 问题即可解决
async def getbrowser(self):
# self.browser = await pyppeteer.launch()
self.browser = await pyppeteer.launch(options={'args': ['--no-sandbox']})
self.page = await self.browser.newPage()
# return await pyppeteer.launch()
完毕!
补充:
最近发现环境原因也可能导致上面的错误。
解决办法如下:
yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y
更多推荐
已为社区贡献3条内容
所有评论(0)