'ubuntu python playright headless true get wrong page

ubuntu python playright headless true get wrong page, how to solve?

from playwright.sync_api import Playwright, sync_playwright
playwright = sync_playwright().start()
playwright.chromium.launch(headless=True, timeout=180 * 1000)
context = browser.new_context()
page = context.new_page()
page.goto('https://www.duda.co/login')
page.wait_for_load_state('networkidle')

page.fill('input[name=userName]', '')

get error page,source code

<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>


<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
</body></html>

if playwright headless=False in mac or window, return to normal page,but i use ubuntu,



Solution 1:[1]

Your target site probably doesn't like the default user agent of Playwright, which is why you have to provide your own:

page = context.new_page(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vaviloff