-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proxy removes cookies #117
Comments
Thanks for the report, I can reproduce with the following spider and a mitmproxy instance running locally: from scrapy import Request, Spider
class PlaywrightSpiderWithProxy(Spider):
name = "proxy-spider"
custom_settings = {
"LOG_LEVEL": "INFO",
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",
"DOWNLOAD_HANDLERS": {
"http": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
# "https": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
},
"PLAYWRIGHT_LAUNCH_OPTIONS": {
"proxy": {
# on a separate terminal:
# ./mitmproxy --proxyauth "user:pass"
"server": "http://127.0.0.1:8080",
"username": "user",
"password": "pass",
},
},
}
def start_requests(self):
yield Request(
url="http://httpbin.org/headers",
meta={"playwright": True},
cookies={"foo": "bar"},
)
def parse(self, response):
print(response.request.headers["Cookie"])
print(response.text) The cookie is in the request headers, however no "Cookie" header was received by the server:
Without configuring the proxy:
The interesting thing is that at this point, |
This seems to be an upstream thing, I just opened microsoft/playwright#16439 asking about it. |
@elacuesta I'm experiencing the same issue. What's the proper way to set cookies in the whole context? |
To set cookies for a whole context at the Playwright level I'd say there are at least 3 ways:
Examples for 2 & 3 can be found in the contexts.py file within the examples directory. There's also an example on accessing the context in a callback for (1) in these lines. To be clear, I don't know if these methods work to avoid skipping the cookies when using proxies, please report back your findings if you can. |
Is the issue similar to #4717 ? |
Without proxy, cookie applied correctly. But when I use proxy (brightdata), then the cookie is not applied. Did I miss anything?
settings.py
The text was updated successfully, but these errors were encountered: