Ubuntu 22.04 上的 Playwright-Python 脚本,使用 Flask + Gunicorn。剧作家错误异常(“从驱动程序读取时连接关闭”)

问题描述 投票:0回答:1

我有一个 Flask 应用程序,它有一个路由,可以触发使用 ngnix 在 ubuntu 22.04 上安装 Playwright 脚本。然而,剧作家的脚本似乎没有触发,因为它不断收到错误。剧作家错误异常(“从驱动程序读取时连接关闭”)

我已尝试重新安装,但仍然没有反应。我尝试通过子进程调用来运行它,但它也无法运行并出现相同的错误。

我确实想知道是否是端口配置导致了此问题,或者 Playwright 无法找到其路径。鉴于剧作家脚本通过 python3 playwrightscript.py 工作得非常好。只是在尝试通过 Flask API 调用脚本时不起作用。

我确实想知道是否有人知道我可以使用的替代方法或此问题的解决方案,因为我已尝试在网上寻找解决方案,但似乎找不到任何可以解决此问题的方法。

#the playwright script is sync and call start in this method where the script gives the error.
playwright = sync_playwright().start()

如有任何帮助,我们将不胜感激。

ubuntu flask gunicorn playwright-python
1个回答
0
投票

这可能是由以下两个因素之一引起的:

  1. 您的操作系统版本较旧,没有所需的驱动程序。检查https://playwright.dev/python/docs/intro#system-requirements

  2. 浏览器路径不正确,请尝试:

    导出 PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers
    剧作家安装 chromium

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.