我最近在 heroku 部署了一个应用程序。它使用 python pyppeteer 包。在 repl.it 上测试时我没有遇到任何问题。但不幸的是,在 heroku 中,浏览器不断崩溃。
我使用 requirements.txt 来安装 pyppeteer 包。我还尝试使用 apt heroku buildpack 来安装 pupeteer 按照此处工作所需的要求
我的程序:
async def mainer(link, path, is_image):
browser = await launch(args=['--no-sandbox'])
page = await browser.newPage()
await page.goto(link)
if is_image:
await page.screenshot({'path': f'{path}', 'fullPage': True, 'type': 'png'})
else:
await page.pdf({'path': f'{path}'})
await browser.close()
这是来自 heroku 的完整回溯错误:
2020-05-14T19:39:50.115643+00:00 app[worker.1]: await handler.callback(self.client, *args)
2020-05-14T19:39:50.115644+00:00 app[worker.1]: File "/app/plugins/downloader.py", line 61, in cb_
2020-05-14T19:39:50.115645+00:00 app[worker.1]: await mainer(url,file,mode)
2020-05-14T19:39:50.115645+00:00 app[worker.1]: File "/app/plugins/downloader.py", line 13, in mainer
2020-05-14T19:39:50.115646+00:00 app[worker.1]: browser = await launch(args=['--no-sandbox'])
2020-05-14T19:39:50.115646+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 305, in launch
2020-05-14T19:39:50.115647+00:00 app[worker.1]: return await Launcher(options, **kwargs).launch()
2020-05-14T19:39:50.115648+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 166, in launch
2020-05-14T19:39:50.115648+00:00 app[worker.1]: self.browserWSEndpoint = get_ws_endpoint(self.url)
2020-05-14T19:39:50.115648+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 225, in get_ws_endpoint
2020-05-14T19:39:50.115649+00:00 app[worker.1]: raise BrowserError('Browser closed unexpectedly:\n')
2020-05-14T19:39:50.115649+00:00 app[worker.1]: pyppeteer.errors.BrowserError: Browser closed unexpectedly:
2020-05-14T19:39:50.115650+00:00 app[worker.1]: