playwright-python
playwright-python copied to clipboard
[BUG] asyncio.exceptions.CancelledError if all_headers() is called on failed request and page is reused (Chromium)
Context:
- Playwright Version: 1.26.0
- Operating System: Mac
- Python version: 3.9
- Browser: Chromium
Code Snippet
- Run
python test.pyfor normal behavior:TimeoutError, {headers}, Error - Run
python test.py failfor failing behavior:TimeoutError, {headers}, asyncio.Exceptiontest.py:
import sys
from playwright.sync_api import sync_playwright
def check_request(request):
try:
print(request.headers)
print(request.all_headers()) # Fails
print(request.headers_array()) # Fails
except Exception as e:
print(e.__class__.__name__)
def run(playwright, fail):
browser = playwright.chromium.launch()
# browser = playwright.firefox.launch() # requestfailed not called?
context = browser.new_context()
page = context.new_page()
page.on("requestfailed", check_request)
url = "http://example.com"
try:
page.goto(url, timeout=1)
except Exception as e:
print(e.__class__.__name__)
if fail:
page.goto(url)
browser.close()
if __name__ == '__main__':
with sync_playwright() as playwright:
fail = len(sys.argv) > 1
run(playwright, fail)
Describe the bug
The request.all_headers() and request.headers_array() methods stall if another request is done with the same page after an error. This results in an asyncio.exceptions.CancelledError at the end of the script.
If the methods are called on the last request of a page, an error is raised instead. I would expect to always receive the error (or the headers, as the normal request.headers works).
For Firefox and WebKit, the requestfailed event does not seem to be called for timedout requests, so the above code does not generate any errors for them.