thesadru / genshinstats

PLEASE USE GENSHIN.PY A python library that can get the stats of Genshin Impact players using Mihoyo's API. PLEASE USE GENSHIN.PY
https://thesadru.github.io/pdoc/genshinstats/
MIT License
265 stars 38 forks source link

get_all_user_data fails with a 10103 error and no message #28

Closed moreside closed 3 years ago

moreside commented 3 years ago

I started receiving an unrecognized error after attempting to fetch user data using accounts generated with your account creator tool. It occasionally works, but other times it responds with a 10103 error which has no associated message:

Traceback (most recent call last):
  File "c:\Users\Will\Desktop\projects\genshin-impact-spiral-abyss-stats\test.py", line 14, in <module>
    user_data = get_all_user_data(606355280)
  File "C:\Python39\lib\site-packages\genshinstats\genshinstats.py", line 232, in get_all_user_data    
    data = get_user_stats(uid, cookie)
  File "C:\Python39\lib\site-packages\genshinstats\genshinstats.py", line 181, in get_user_stats       
    data = fetch_endpoint(
  File "C:\Python39\lib\site-packages\genshinstats\genshinstats.py", line 167, in fetch_endpoint
    return _request(method, url, cookies=cookie, **kwargs)
  File "C:\Python39\lib\site-packages\genshinstats\utils.py", line 109, in inner
    return func(*args, **kwargs)
  File "C:\Python39\lib\site-packages\genshinstats\genshinstats.py", line 140, in _request
    raise_for_error(data)
  File "C:\Python39\lib\site-packages\genshinstats\errors.py", line 80, in raise_for_error
    raise error
genshinstats.errors.GenshinStatsException: 10103 Error ()

Here's a minimal example of the code I'm using. accounts.json is untouched after it's generated by the account creator.

from genshinstats import get_all_user_data, set_cookies
from json import load

def load_json(filename):
    with open(filename) as json_file:
        return load(json_file)

accounts = load_json("accounts.json")
cookies = [account["cookies"] for account in accounts]
set_cookies(*cookies)

user_data = get_all_user_data(123456789)
print(user_data)

What does this error mean?

thesadru commented 3 years ago

Oh looks like my account creator has a bug then, 10103 means your account exists but doesn't have a hoyolab username. I'll try and see if I can make some fix with how the hoyolab accounts are made.

moreside commented 3 years ago

I believe I've spotted the problem. When I run the account creator, at the end of the create_hoyolab_account stage it refreshes the page before hoyolab can register the account properly. I added a simple time.sleep before the refresh at the end of that function, and the accounts it generates are now all usable. So yeah, no problems on genshinstats's end, although mapping that error code to a message would probably be useful.

thesadru commented 3 years ago

Thanks, I thought it was caused by something completely different. I'm sorry it took so long, I was a bit busy lately.