Skip to content

Commit 81d9b6f

Browse files
committed
fix: illegal wechat cookies request
1 parent 27c9093 commit 81d9b6f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

maimai_py/providers/wechat.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,28 @@ async def get_player(self, identifier: PlayerIdentifier, client: "MaimaiClient")
120120

121121
@retry(stop=stop_after_attempt(3), retry=retry_if_exception_type(RequestError), reraise=True)
122122
async def get_identifier(self, code: Union[str, dict[str, str]], client: "MaimaiClient") -> PlayerIdentifier:
123+
wechat_ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6307001e)"
124+
123125
if isinstance(code, dict) and all([code.get("r"), code.get("t"), code.get("code"), code.get("state")]):
124126
headers = {
125-
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6307001e)",
126127
"Host": "tgk-wcaime.wahlap.com",
128+
"Upgrade-Insecure-Requests": "1",
127129
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
130+
"Sec-Fetch-Site": "none",
131+
"Sec-Fetch-Mode": "navigate",
132+
"Sec-Fetch-User": "?1",
133+
"Sec-Fetch-Dest": "document",
134+
"Accept-Encoding": "gzip, deflate, br",
135+
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
128136
}
129137
resp = await client._client.get(
130-
"https://tgk-wcaime.wahlap.com/wc_auth/oauth/callback/maimai-dx", params=code, headers=headers
138+
"https://tgk-wcaime.wahlap.com/wc_auth/oauth/callback/maimai-dx",
139+
headers={"User-Agent": wechat_ua, **headers},
140+
params=code,
131141
)
132142
if resp.status_code == 302 and resp.next_request:
133-
resp_next = await client._client.get(resp.next_request.url, headers=headers)
143+
resp_next = await client._client.get(resp.next_request.url, headers={"User-Agent": wechat_ua})
144+
print(resp_next)
134145
return PlayerIdentifier(credentials=dict(resp_next.cookies))
135146
else:
136147
raise InvalidWechatTokenError("Invalid or expired Wechat token")

0 commit comments

Comments
 (0)