Remove 'secure' attribute from cookies in ProxyGenerator to ensure co…#581
Open
Luen wants to merge 2 commits intoscholarly-python-package:developfrom
Open
Remove 'secure' attribute from cookies in ProxyGenerator to ensure co…#581Luen wants to merge 2 commits intoscholarly-python-package:developfrom
Luen wants to merge 2 commits intoscholarly-python-package:developfrom
Conversation
…mpatibility with httpx Cookies.set()
…or citedby URL extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix cookie transfer after CAPTCHA: strip secure before httpx Cookies.set()
When Google Scholar returns a CAPTCHA, the flow uses a browser to solve it, then copies cookies from the browser (Selenium) back into the httpx session so later requests use the same session. That copy step was raising:
TypeError: Cookies.set() got an unexpected keyword argument 'secure'
After that, the code retried with a new session, so the solved CAPTCHA session was effectively lost.
In _proxy_generator.py, _handle_captcha2() does:
Wait for the user to solve the CAPTCHA in the browser.
Call self._get_webdriver().get_cookies() (Selenium), which returns dicts that include browser-specific keys such as httpOnly, expiry, sameSite, and secure.
Strip only httpOnly, expiry, and sameSite, then call self._session.cookies.set(**cookie) (httpx).
httpx’s Cookies.set() does not accept a secure keyword. Passing the Selenium cookie dict as **cookie therefore included secure and triggered the TypeError.
Before calling self._session.cookies.set(**cookie), remove the secure key from each cookie dict, in the same way as the other non-httpx fields:
In _handle_captcha2(), add: cookie.pop("secure", None) after the existing pop calls for httpOnly, expiry, and sameSite.
With this, only supported arguments are passed to Cookies.set(), the cookie transfer completes, and the session continues to work after CAPTCHA solving without retrying due to this error.