Closed Cabu closed 11 months ago
Possible patch that work for me:
In class GoogleV2(Tse), add the following method:
def get_consent_post(self, consent_html: str) -> dict:
et = lxml.etree.HTML(consent_html)
form_element = et.xpath('.//form[1]')
post_url = form_element[0].attrib.get('action') if form_element else 'https://consent.google.com/save'
input_elements = form_element[0].xpath('.//input[@type="hidden"]')
post_values = {input.attrib.get('name'): input.attrib.get('value') for input in input_elements}
return post_url, post_values
in the method google_api, replace around line 591
if 'consent.google.com' == urllib.parse.urlparse(r.url).hostname:
self.host_headers.update({'cookie': self.get_consent_cookie(r.text)})
host_html = self.session.get(self.host_url, headers=self.host_headers, timeout=timeout, proxies=proxies).text
else:
by
if 'consent.google.com' == urllib.parse.urlparse(r.url).hostname:
post_url, post_form = self.get_consent_post(r.text)
host_html = self.session.post(post_url, data=post_form, headers=self.host_headers, timeout=timeout, proxies=proxies).text
else:
self.host_headers.update({'cookie': self.get_consent_cookie(r.text)}) and the method get_consent_cookie() doesn't work anymore...
Confirmation! self.host_headers.update({'cookie': self.get_consent_cookie(r.text)}) and the method get_consent_cookie() are not necessary anymore and could be deleted!
@Cabu Copy that, sir!
@Cabu Bro, you can attention this -> #35 and #57
I don't know about #35, but my patch clearly solve #57 in the proper way (simulating the click on "Accept all") without the proposed make_temp_language_map workaround.
Please upgrade v5.8.5
5.8.5 doesn't work for me. get_languages get blocked by the cookie consent form :(
Confirmation! self.host_headers.update({'cookie': self.get_consent_cookie(r.text)}) and the method get_consent_cookie() are not necessary anymore and could be deleted!
@Cabu ?
Your new version deleted the "get_consent_cookie" that doesn't worked anymore and that is nice, but it doesn't implement the patch with "get_consent_post" I proposed to work around the European cookie consent kit google implemented.
i updated my proposed patch accordingly.
@Cabu Bro, for your contributions, welcome to your PR.
@Cabu Bro, please pip install --upgrade translators==5.8.6
.
Debug Tips
What happened?
The trick to get anew the host_url with the consent_cookie (server.py lines 591 to 593) doesn't seems to work anymore. It seems that now a POST with a bung of inputs should be made.
APP Version
5.8.3
Python Version
3.9 (Default)
Runtime Environment
Linux CentOS (Default)
Country/Region
Belgium
Relevant log output
Screenshots
No response
Code of Conduct