Open KT-Yeh opened 7 months ago
Same. This worked recently, so the code is correct
cookies = {"ltuid": ltuid, "ltoken": ltoken,
"ltuid_v2": ltuid, "ltoken_v2": ltoken}
client = genshin.Client(cookies)
account = await get_accounts(client)[0]
notes = await client.get_notes(account.uid)
File "main.py", line 60, in get_Original_Resin
notes = await client.get_notes(account.uid)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/components/chronicle/genshin.py", line 119, in get_genshin_notes
data = await self._request_genshin_record("dailyNote", uid, lang=lang, cache=False)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/components/chronicle/genshin.py", line 52, in _request_genshin_record
return await self.request_game_record(
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/components/chronicle/base.py", line 60, in request_game_record
data = await self.request_hoyolab(url, lang=lang, region=region, **kwargs)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/components/base.py", line 433, in request_hoyolab
data = await self.request(url, method=method, params=params, data=data, headers=headers, **kwargs)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/components/base.py", line 331, in request
response = await self.cookie_manager.request(
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/manager/managers.py", line 264, in request
return await self._request(method, url, cookies=self.cookies, **kwargs)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/ratelimit.py", line 24, in inner
x = await func(*args, **kwargs)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/client/manager/managers.py", line 158, in _request
errors.raise_for_retcode(data)
File "/home/runner/genshin-api/venv/lib/python3.10/site-packages/genshin/errors.py", line 256, in raise_for_retcode
raise exctype(data, msg)
genshin.errors.InvalidCookies: [10001] Cookies are not valid.
Python 3.10.8
genshin 1.6.1
It seems quite weird ... I've tried two cases, token_v1 and token_v2 : (Test date : 2023-12-01 11:45:00 UTC+8) (genshin.py 1.6.1 , Python 3.10.11 & Python 3.8.15)
token_v1
:cookies = {"ltuid": ltuid, "ltoken": ltoken}
client = genshin.Client(cookies)
data = await client.get_game_accounts()
it does work correctly, even without an edition in genshin\client\manager\managers.py
[{"lang":"en-us", "game_biz":"hk4e_global", "uid":901465968, "level":60, "nickname":"夜芷冰", "server":"os_cht", "server_name":"TW, HK, MO Server"}, ...]
token_v2
:cookies = {
"ltuid_v2": ltuid_v2,
"ltoken_v2": ltoken_v2,
"account_id_v2": account_id_v2,
"cookie_token_v2": cookie_token_v2,
"account_mid_v2": account_mid_v2,
"ltmid_v2": ltmid_v2
}
client = genshin.Client(cookies)
data = await client.get_game_accounts()
it will always display "genshin.errors.InvalidCookies: [-100] Cookies are not valid." , which edition made in line 149 - 151 of genshin\client\manager\managers.py
seems didn't help in this moment...
Howdy, I'm running into the same errors and commenting out the lines on the managers.py page is still saying the cookies are wrong. Has anyone had any luck since then?
Then it is likely that your cookies are actually invalid.
Is there somewhere else I need to go to get the cookies? I'm copying them directly from the cookies storage space in the developer panel. I've used both "ltuid"/"ltoken" and "ltuid_v2"/"ltoken_v2" as keys. Where else do I need to go for the cookies?
Can you join the discord server so its easier for me to debug for you? https://discord.gg/dbXpMDw9nv
Is there somewhere else I need to go to get the cookies? I'm copying them directly from the cookies storage space in the developer panel. I've used both "ltuid"/"ltoken" and "ltuid_v2"/"ltoken_v2" as keys. Where else do I need to go for the cookies?
This issue was solved in the discord server by logging out the hoyolab account then logging back in to refresh the cookies.
This solution worked for me:
ltmid_v2
to cookiesNow the final cookies dict looks like that:
cookies = {
"ltuid_v2": int,
"ltmid_v2": str,
"ltoken_v2": str
}
And need to uncheck checkbox "HttpOnly":
This solution worked for me:
- Just add
ltmid_v2
to cookiesNow the final cookies dict looks like that:
cookies = { "ltuid_v2": int, "ltmid_v2": str, "ltoken_v2": str }
And need to uncheck checkbox "HttpOnly":
Worked for me too. Maybe add it to the README and/or the documentation?
I seem to be getting this error too, despite also adding ltmid_v2
, but only for Star Rail's trailblazer monthly report
cookie = {
"ltmid_v2": "",
"ltoken_v2": "",
"ltuid_v2": ""
}
async def main():
client = genshin.Client(cookie, game=genshin.Game.STARRAIL, debug=True)
await client.get_game_accounts()
await client.get_starrail_diary()
Genshin's monthly report works fine
@BobbyWibowo, add cookie_token_v2
and replace ltmid_v2
with account_mid_v2
(same value, different name)
@JokelBaf Somehow still doesn't work on my end
Or more like, it is failing before hitting the monthly report API. Probably because of missing ltmid_v2
as the original issue?
But even if I kept ltmid_v2
(as well as account_mid_v2
and cookie_token_v2
), it'll get to monthly report API but still fails like my previous comment 😕
@BobbyWibowo, can you try to refresh your cookies by logging out and back in? The following code works fine for me:
import asyncio
import genshin
cookie = {
"ltoken_v2": "",
"cookie_token_v2": "",
"account_mid_v2": "",
"ltuid_v2": "",
}
async def main():
client = genshin.Client(cookie, game=genshin.Game.STARRAIL, debug=True)
d = await client.get_starrail_diary()
print(d)
asyncio.run(main())
@JokelBaf Ah cr*p, my bad... Aside from relogging, I also realized that I didn't copy cookie_token_v2
properly before this. There was a -
character, so select-all by double-clicking didn't actually highlight the whole string (no wonder it felt oddly shorter). In short, I probably did have invalid cookies altogether.
I can confirm it works now. Likely would've earlier too, if I actually copied my cookies properly.
ltmid_v2
also seemed to be not needed, even with other API routes in my project, in context of also having both account_mid_v2
and cookie_token_v2
instead.
Either way, many thanks!
Using the ltoken_v2 and ltuid_v2 cookies to make API requests, the Cookie manager updates the cookie by adding ltmid_v2 (
DEBUG:genshin.client.manager.managers:Updating cookies for 0: {'ltmid_v2', 'aliyungf_tc'}
). Subsequently, any requests will result in an Invalid Cookie.If lines 149 to 151 in
genshin\client\manager\managers.py
are commented out, thus not updating to add ltmid_v2, the same cookie can be used to make normal API requests.Same cookie and same code: