MCPcopy
hub / github.com/Sophomoresty/gemini-web2api / _get_page_tokens

Function _get_page_tokens

gemini_web2api/multimodal.py:14–38  ·  view source on GitHub ↗

Fetch WIZ_global_data tokens from Gemini page (Push-ID, X-Client-Pctx).

()

Source from the content-addressed store, hash-verified

12
13
14def _get_page_tokens() -> dict:
15 """Fetch WIZ_global_data tokens from Gemini page (Push-ID, X-Client-Pctx)."""
16 headers = {
17 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
18 }
19 cookie_str, sapisid = load_cookie()
20 if cookie_str:
21 headers["Cookie"] = cookie_str
22 try:
23 req = urllib.request.Request("https://gemini.google.com/app", headers=headers)
24 resp = urllib.request.urlopen(req, context=_get_ssl_ctx(), timeout=30)
25 html = resp.read().decode()
26 tokens = {}
27 for key, pattern in [
28 ("push_id", r'"qKIAYe":"([^"]+)"'),
29 ("pctx", r'"Ylro7b":"([^"]+)"'),
30 ("at", r'"thykhd":"([^"]+)"'),
31 ]:
32 m = re.search(pattern, html)
33 if m:
34 tokens[key] = m.group(1)
35 return tokens
36 except Exception as e:
37 log(f"Page token fetch failed: {e}")
38 return {}
39
40
41_page_tokens_cache = {"tokens": {}, "ts": 0}

Callers 1

_cached_page_tokensFunction · 0.85

Calls 3

_get_ssl_ctxFunction · 0.85
load_cookieFunction · 0.70
logFunction · 0.70

Tested by

no test coverage detected