关于使用编剧Python脚本部署报错github动作
About using playwright's Python script deployment to report an error on github action
- 部分代码
我的代码:
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')
- 错误信息
我的代码在本地可以运行成功,但是部署到GitHubaction时(我按照官方文档写的yaml)会报错:
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.
希望大家能帮帮我,谢谢
像这样尝试 Firefox 浏览器:
from playwright.sync_api import sync_playwright
chromium = playwright.firefox
browser = chromium.launch(headless=False)
page = browser.new_page()
page.goto(url)
- 部分代码
我的代码:
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')
- 错误信息
我的代码在本地可以运行成功,但是部署到GitHubaction时(我按照官方文档写的yaml)会报错:
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.
希望大家能帮帮我,谢谢
像这样尝试 Firefox 浏览器:
from playwright.sync_api import sync_playwright
chromium = playwright.firefox
browser = chromium.launch(headless=False)
page = browser.new_page()
page.goto(url)