question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Overwrite Headers for Python's `Route.continue_`

See original GitHub issue

Hi all! I first want to say that I love Playwright – it is incredibly seamless and lightning fast. From my experience so far, it has a simple yet powerful API, and is a lot less clunky than Selenium.

My team is trying to use it to render PDFs, and we need to set the Origin header to avoid CORS issues. I have found an issue that has plagued me on Ubuntu and MacOS Big Sur, with Python 3.9.5 and Playwright (Python) 1.12.1.

Using a modified Spec example, here is our issue:

from playwright.sync_api import sync_playwright

def handle(route, request):
    headers = {
        **request.headers,
        'foo': 'bar', # set 'foo' header
        'origin': 'literally_anywhere'
    }
    route.continue_(headers=headers)

with sync_playwright() as pw:
    browser = pw.chromium.launch()
    page = browser.new_page()
    page.route("**/*", handle)
    page.on('request', lambda request: print(f'====request headers: ({request.url})====\n{request.headers}\n'))
    browser.close()

'foo' is being set erratically – only on two of the page requests that are logged. 'origin' is never set. In addition, the spec example cites being able to set 'origin': None, but for me it throws

playwright._impl._api_types.Error: headers[4].value: expected string, got object

Installation procedure was as follows:

# (in a python3 venv virtual environment)
pip install playwright
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 python -m playwright install
playwright install chromium

Thank you in advance for any help! Please let me know if this is just a configuration issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mxschmittcommented, Jun 21, 2021

I digged into it. The reason is at least in the reproducible, that it’s based on redirects which is currently an upstream limitation. When you are using https://www.google.com it works. Their redirect chain is: http://google.com -> https://google.com -> https://www.google.com.

PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 python -m playwright install this will like result in doing nothing. You are saying basically, hey install browsers but the skip env var is set, so its not installing anything at all.

0reactions
mxschmittcommented, Jun 24, 2021

Closed for now, lets reopen if the problem is still persistent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Having trouble maintaining order of Session headers ...
You'll have to override the default header completely. The way i can think to do this is to use a Session , and...
Read more >
Is that a way modify request cookies before it perform ... - GitHub
and, I'm confused that, it would trigger keyerror when use route.request.headers["cookie"], but it exist when print the dict directly.
Read more >
Export to CSV with Override and NO Header Row - Python
Solved: I've built a Pythons script the organizes a dataset that is used for an external database and exported it from a File...
Read more >
email: Examples — Python 3.11.1 documentation
Here are a few examples of how to use the email package to read, write, and send simple email messages, as well as...
Read more >
HTTP/1.1: Header Field Definitions
If no Accept header field is present, then it is assumed that the client accepts all media types. If an Accept header field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found