thesadru / genshin.py

Modern API wrapper for Genshin Impact & Honkai Impact 3rd built on asyncio and pydantic. 原神 崩坏3
https://thesadru.github.io/genshin.py
MIT License
379 stars 67 forks source link

Cookie manager updating the V2 cookie results in an InvalidCookie. #151

Open KT-Yeh opened 7 months ago

KT-Yeh commented 7 months ago

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.

cookie = {
    "ltoken_v2": "v2_xxxx",
    "ltuid_v2": xxxxx
}
client = genshin.Client(cookie, lang="zh-tw", debug=True)
await client.get_game_accounts()
await client.get_genshin_notes()
DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie
DEBUG:genshin.client.manager.managers:Updating cookies for 0: {'ltmid_v2', 'aliyungf_tc'}
DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie
---------------------------------------------------------------------------
InvalidCookies                            Traceback (most recent call last)
[test.ipynb Cell 1 line 3
---> [37] await client.get_genshin_notes()

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\chronicle\genshin.py:119](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/chronicle/genshin.py:119), in GenshinBattleChronicleClient.get_genshin_notes(self, uid, lang, autoauth)
    117 """Get genshin real-time notes."""
    118 try:
--> 119     data = await self._request_genshin_record("dailyNote", uid, lang=lang, cache=False)
    120 except errors.DataNotPublic as e:
    121     # error raised only when real-time notes are not enabled
    122     if uid and (await self._get_uid(types.Game.GENSHIN)) != uid:

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\chronicle\genshin.py:33](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/chronicle/genshin.py:33), in GenshinBattleChronicleClient._request_genshin_record(self, endpoint, uid, method, lang, payload, cache)
     30 payload = dict(payload or {})
     31 original_payload = payload.copy()
---> 33 uid = uid or await self._get_uid(types.Game.GENSHIN)
     34 payload = dict(role_id=uid, server=utility.recognize_genshin_server(uid), **payload)
     36 data, params = None, None

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\utility\concurrency.py:31](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/utility/concurrency.py:31), in prevent_concurrency.<locals>.wrapper.<locals>.inner(*args, **kwargs)
     28     lock = asyncio.Lock()
     30 async with lock:
---> 31     return await func(*args, **kwargs)

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\base.py:489](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/base.py:489), in BaseClient._get_uid(self, game)
    486 if self.cookie_manager.multi:
    487     raise RuntimeError("UID must be provided when using multi-cookie managers.")
--> 489 await self._update_cached_uids()
    491 if uid := self.uids.get(game):
    492     return uid

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\base.py:465](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/base.py:465), in BaseClient._update_cached_uids(self)
    463 async def _update_cached_uids(self) -> None:
    464     """Update cached fallback uids."""
--> 465     mixed_accounts = await self.get_game_accounts()
    467     game_accounts: typing.Dict[types.Game, typing.List[hoyolab_models.GenshinAccount]] = {}
    468     for account in mixed_accounts:

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\base.py:446](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/base.py:446), in BaseClient.get_game_accounts(self, lang)
    443 if self.hoyolab_id is None:
    444     warnings.warn("No hoyolab id set, caching may be unreliable.")
--> 446 data = await self.request_hoyolab(
    447     "binding/api/getUserGameRolesByCookie",
    448     lang=lang,
    449     cache=client_cache.cache_key("accounts", hoyolab_id=self.hoyolab_id),
    450 )
    451 return [hoyolab_models.GenshinAccount(**i) for i in data["list"]]

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\base.py:433](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/base.py:433), in BaseClient.request_hoyolab(self, url, lang, region, method, params, data, headers, **kwargs)
    430 headers = dict(headers or {})
    431 headers.update(ds.get_ds_headers(data=data, params=params, region=region, lang=lang or self.lang))
--> 433 data = await self.request(url, method=method, params=params, data=data, headers=headers, **kwargs)
    434 return data

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\components\base.py:331](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/components/base.py:331), in BaseClient.request(self, url, method, params, data, headers, cache, static_cache, **kwargs)
    327     raise TypeError("Use data instead of json in request.")
    329 await self._request_hook(method, url, params=params, data=data, headers=headers, **kwargs)
--> 331 response = await self.cookie_manager.request(
    332     url,
    333     method=method,
    334     params=params,
    335     json=data,
    336     headers=headers,
    337     **kwargs,
    338 )
    340 # cache
    342 if cache is not None:

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\manager\managers.py:264](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/manager/managers.py:264), in CookieManager.request(self, url, method, **kwargs)
    256 async def request(
    257     self,
    258     url: aiohttp.typedefs.StrOrURL,
   (...)
    261     **kwargs: typing.Any,
    262 ) -> typing.Any:
    263     """Make an authenticated request."""
--> 264     return await self._request(method, url, cookies=self.cookies, **kwargs)

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\ratelimit.py:24](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/ratelimit.py:24), in handle_ratelimits.<locals>.wrapper.<locals>.inner(*args, **kwargs)
     22 for _ in range(tries):
     23     try:
---> 24         x = await func(*args, **kwargs)
     25     except exception:
     26         await asyncio.sleep(delay)

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\client\manager\managers.py:158](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/client/manager/managers.py:158), in BaseCookieManager._request(self, method, str_or_url, cookies, **kwargs)
    155 if data["retcode"] == 0:
    156     return data["data"]
--> 158 errors.raise_for_retcode(data)

File [c:\Users\xns77\.virtualenvs\Genshin-Discord-Bot-IEZBHIyR\lib\site-packages\genshin\errors.py:256](file:///C:/Users/xns77/.virtualenvs/Genshin-Discord-Bot-IEZBHIyR/lib/site-packages/genshin/errors.py:256), in raise_for_retcode(data)
    254 if r in ERRORS:
    255     exctype, msg = ERRORS[r]
--> 256     raise exctype(data, msg)
    258 if "redemption" in m:
    259     raise RedemptionException(data)

InvalidCookies: [-100] Cookies are not valid.

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.

image

Same cookie and same code:

DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie
DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie
DEBUG:genshin.client.components.base:GET https://bbs-api-os.hoyolab.com/game_record/genshin/api/dailyNote?role_id=832901791&server=os_asia
DEBUG:genshin.client.components.base:GET https://webstatic-sea.mihoyo.com/admin/mi18n/bbs_cn/m11241040191111/m11241040191111-zh-tw.json
SuperZombi commented 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
Vocaloid2048 commented 7 months ago

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)

case 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"}, ...]

case 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...

Thx for giving help first!

skyfila commented 6 months ago

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?

seriaati commented 6 months ago

Then it is likely that your cookies are actually invalid.

skyfila commented 6 months ago

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?

seriaati commented 6 months ago

Can you join the discord server so its easier for me to debug for you? https://discord.gg/dbXpMDw9nv

seriaati commented 6 months ago

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.

SuperZombi commented 6 months ago

This solution worked for me:

Now the final cookies dict looks like that:

cookies = {
        "ltuid_v2": int,
        "ltmid_v2": str,
        "ltoken_v2": str
}

And need to uncheck checkbox "HttpOnly": image

soleilvermeil commented 5 months ago

This solution worked for me:

  • Just add ltmid_v2 to cookies

Now the final cookies dict looks like that:

cookies = {
        "ltuid_v2": int,
        "ltmid_v2": str,
        "ltoken_v2": str
}

And need to uncheck checkbox "HttpOnly": image

Worked for me too. Maybe add it to the README and/or the documentation?

BobbyWibowo commented 1 month ago

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()
logs ```log DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie DEBUG:genshin.client.manager.managers:Updating cookies for xxxxxxxx: {'aliyungf_tc'} DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie DEBUG:genshin.client.components.base:GET https://sg-public-api.hoyolab.com/event/srledger/month_info?uid=xxxxxxxx®ion=prod_official_asia&month=202405&lang=en-us Traceback (most recent call last): File "/home/bobby/src/genshin-checkin-helper/test.py", line 16, in asyncio.run(main()) File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/bobby/src/genshin-checkin-helper/test.py", line 13, in main await client.get_starrail_diary() File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/diary.py", line 176, in get_starrail_diary data = await self.request_ledger(uid, game=game, month=month, lang=lang, cache=cache_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/diary.py", line 134, in request_ledger return await self.request(url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 332, in request response = await self.cookie_manager.request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/manager/managers.py", line 268, in request return await self._request(method, url, cookies=self.cookies, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/ratelimit.py", line 25, in inner x = await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/manager/managers.py", line 159, in _request errors.raise_for_retcode(data) File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/errors.py", line 274, in raise_for_retcode raise exctype(data, msg) genshin.errors.InvalidCookies: [-100] Cookies are not valid. ```

Genshin's monthly report works fine

jokelbaf commented 1 month ago

@BobbyWibowo, add cookie_token_v2 and replace ltmid_v2 with account_mid_v2 (same value, different name)

BobbyWibowo commented 1 month ago

@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?

logs ``` DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie DEBUG:genshin.client.manager.managers:Updating cookies for 0: {'ltmid_v2', 'aliyungf_tc'} DEBUG:genshin.client.components.base:GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie Traceback (most recent call last): File "/home/bobby/src/genshin-checkin-helper/test.py", line 17, in asyncio.run(main()) File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/bobby/src/genshin-checkin-helper/test.py", line 14, in main await client.get_starrail_diary() File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/diary.py", line 172, in get_starrail_diary uid = uid or await self._get_uid(game) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/utility/concurrency.py", line 32, in inner return await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 490, in _get_uid await self._update_cached_uids() File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 466, in _update_cached_uids mixed_accounts = await self.get_game_accounts() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 447, in get_game_accounts data = await self.request_hoyolab( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 434, in request_hoyolab data = await self.request(url, method=method, params=params, data=data, headers=headers, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/components/base.py", line 332, in request response = await self.cookie_manager.request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/manager/managers.py", line 268, in request return await self._request(method, url, cookies=self.cookies, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/ratelimit.py", line 25, in inner x = await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/client/manager/managers.py", line 159, in _request errors.raise_for_retcode(data) File "/home/bobby/.cache/pypoetry/virtualenvs/genshin-checkin-helper-ZCH6EzeK-py3.11/lib/python3.11/site-packages/genshin/errors.py", line 274, in raise_for_retcode raise exctype(data, msg) genshin.errors.InvalidCookies: [-100] Cookies are not valid. ```

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 😕

jokelbaf commented 1 month ago

@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())
BobbyWibowo commented 1 month ago

@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!