首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于如何使用剧作家的Python脚本部署来报告github操作的错误

关于如何使用剧作家的Python脚本部署来报告github操作的错误
EN

Stack Overflow用户
提问于 2022-03-08 15:44:08
回答 1查看 414关注 0票数 0
  • 部分代码

我的代码:

代码语言:javascript
复制
 def hfut_sign(act, pwd):
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        context = browser.new_context()       
        page = context.new_page()
        page.goto(url)
        page.locator("button:has-text(\"统一身份认证\")").click()       
        page.locator("[placeholder=\"账号\"]").fill(act)
        page.locator("[placeholder=\"密码\"]").fill(pwd)
        page.locator("input:has-text(\"登录\")").click()
        try:
            page.locator("text=提交").click(timeout=0.3)
            page.locator("text=返回").click(timeout=0.3)
            print(f'{act} sign in successfully')
            context.close()
            browser.close()
        except:
            context.close()
            browser.close()
            print(f'{act} have signed in')

  • 错误消息

我的代码可以在本地成功运行,但是当部署到GitHub操作(我根据正式文档编写了yaml )时,将报告一个错误:

代码语言:javascript
复制
    Loop <_UnixSelectorEventLoop running=False closed=True debug=False> that handles pid 1602 is closed
Traceback (most recent call last):
  File "hfut_lite.py", line 33, in <module>
    hfut_sign(account, password)
  File "hfut_lite.py", line 7, in hfut_sign
    browser = p.chromium.launch(headless=False)
  File "/home/runner/.local/lib/python3.8/site-packages/playwright/sync_api/_generated.py", line 11417, in launch
    self._sync(
  File "/home/runner/.local/lib/python3.8/site-packages/playwright/_impl/_sync_base.py", line 111, in _sync
    return task.result()
  File "/home/runner/.local/lib/python3.8/site-packages/playwright/_impl/_browser_type.py", line 90, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/home/runner/.local/lib/python3.8/site-packages/playwright/_impl/_connection.py", line 39, in send
    return await self.inner_send(method, params, False)
  File "/home/runner/.local/lib/python3.8/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.Error: Browser closed.
==================== Browser output: ====================
<launching> /home/runner/.cache/ms-playwright/chromium-965416/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-YI0ALF --remote-debugging-pipe --no-startup-window
<launched> pid=1734
[pid=1734][err] [1734:1734:0308/151713.654266:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
[pid=1734][err] [1734:1734:0308/151713.654333:ERROR:env.cc(225)] The platform failed to initialize.  Exiting.
=========================== logs ===========================
<launching> /home/runner/.cache/ms-playwright/chromium-965416/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-YI0ALF --remote-debugging-pipe --no-startup-window
<launched> pid=1734
[pid=1734][err] [1734:1734:0308/151713.654266:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
[pid=1734][err] [1734:1734:0308/151713.654333:ERROR:env.cc(225)] The platform failed to initialize.  Exiting.
============================================================
Error: Process completed with exit code 1.

我希望你能帮我,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-28 11:10:23

试试像这样的Firefox浏览器:

代码语言:javascript
复制
from playwright.sync_api import sync_playwright

chromium = playwright.firefox
browser = chromium.launch(headless=False)
page = browser.new_page()
page.goto(url)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71397730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档