Module genshin.errors
Errors received from the API.
Functions
def check_for_geetest(data: dict[str, typing.Any]) ‑> None
-
Expand source code
def check_for_geetest(data: dict[str, typing.Any]) -> None: """Check if geetest was triggered during the request and raise an error if so.""" retcode = data.get("retcode") if retcode is not None and retcode in GEETEST_RETCODES: raise GeetestError(data) if not data.get("data"): # if is an error return gt_result = data["data"].get("gt_result", data["data"]) if ( gt_result.get("risk_code") != 0 and gt_result.get("gt") and gt_result.get("challenge") and gt_result.get("success") != 0 ): raise DailyGeetestTriggered(data, gt=gt_result.get("gt"), challenge=gt_result.get("challenge"))
Check if geetest was triggered during the request and raise an error if so.
def raise_for_retcode(data: dict[str, typing.Any]) ‑> NoReturn
-
Expand source code
def raise_for_retcode(data: dict[str, typing.Any]) -> typing.NoReturn: """Raise an equivalent error to a response. game record: 10001 = invalid cookie 101xx = generic errors authkey: -100 = invalid authkey -101 = authkey timed out code redemption: 20xx = invalid code or state -107x = invalid cookies daily reward: -500x = already claimed the daily reward """ r, m = data.get("retcode", 0), data.get("message", "") if m.startswith("authkey"): if r == -100: raise InvalidAuthkey(data) elif r == -101: raise AuthkeyTimeout(data) else: raise AuthkeyException(data) if r in ERRORS: exctype, msg = ERRORS[r] raise exctype(data, m or msg) if "redemption" in m: raise RedemptionException(data) raise GenshinException(data)
Raise an equivalent error to a response.
game record: 10001 = invalid cookie 101xx = generic errors authkey: -100 = invalid authkey -101 = authkey timed out code redemption: 20xx = invalid code or state -107x = invalid cookies daily reward: -500x = already claimed the daily reward
Classes
class AccountMuted (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class AccountMuted(GenshinException): """Account is muted.""" retcode = 2010 msg = "Account is muted."
Account is muted.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class AccountNotFound (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class AccountNotFound(GenshinException): """Tried to get data with an invalid uid.""" msg = "Could not find user; uid may be invalid."
Tried to get data with an invalid uid.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class AlreadyClaimed (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class AlreadyClaimed(GenshinException): """Already claimed the daily reward today.""" retcode = -5003 msg = "Already claimed the daily reward today."
Already claimed the daily reward today.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class AuthkeyException (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class AuthkeyException(GenshinException): """Base error for authkeys."""
Base error for authkeys.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Subclasses
Class variables
var msg : str
var original : str
var retcode : int
class AuthkeyTimeout (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class AuthkeyTimeout(AuthkeyException): """Authkey has timed out.""" retcode = -101 msg = "Authkey has timed out."
Authkey has timed out.
Ancestors
- AuthkeyException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class CookieException (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class CookieException(GenshinException): """Base error for cookies."""
Base error for cookies.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Subclasses
Class variables
var msg : str
var original : str
var retcode : int
class DailyGeetestTriggered (response: Mapping[str, Any], *, gt: str, challenge: str)
-
Expand source code
class DailyGeetestTriggered(GenshinException): """Geetest triggered during daily reward claim.""" msg = "Geetest triggered during daily reward claim." gt: str challenge: str def __init__(self, response: typing.Mapping[str, typing.Any], *, gt: str, challenge: str) -> None: self.gt = gt self.challenge = challenge super().__init__(response)
Geetest triggered during daily reward claim.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var challenge : str
var gt : str
var msg : str
class DataNotPublic (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class DataNotPublic(GenshinException): """User hasn't set their data to public.""" msg = "User's data is not public."
User hasn't set their data to public.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class GeetestError (response: dict[str, typing.Any])
-
Expand source code
class GeetestError(GenshinException): """Geetest triggered during the battle chronicle API request.""" def __init__(self, response: dict[str, typing.Any]) -> None: super().__init__(response) msg = "Geetest triggered during the battle chronicle API request."
Geetest triggered during the battle chronicle API request.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class GenshinException (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class GenshinException(Exception): """A base genshin exception.""" retcode: int = 0 original: str = "" msg: str = "" def __init__( self, response: typing.Optional[typing.Mapping[str, typing.Any]] = None, msg: typing.Optional[str] = None ) -> None: response = response or {} self.retcode = response.get("retcode", self.retcode) self.original = response.get("message", "") self.msg = msg or self.msg or self.original if self.retcode and f"[{self.retcode}]" not in self.msg: msg = f"[{self.retcode}] {self.msg}" else: msg = self.msg super().__init__(msg) def __repr__(self) -> str: response = {"retcode": self.retcode, "message": self.original} args = [repr(response)] if self.msg != self.original: args.append(repr(self.msg)) return f"{type(self).__name__}({', '.join(args)})" @property def response(self) -> typing.Mapping[str, typing.Any]: return {"retcode": self.retcode, "message": self.original, "data": None}
A base genshin exception.
Ancestors
- builtins.Exception
- builtins.BaseException
Subclasses
- genshin.errors.AccountDoesNotExist
- genshin.errors.AccountHasLocked
- genshin.errors.AccountLoginFail
- AccountMuted
- AccountNotFound
- AlreadyClaimed
- AuthkeyException
- CookieException
- DailyGeetestTriggered
- DataNotPublic
- GeetestError
- genshin.errors.IncorrectGameAccount
- genshin.errors.IncorrectGamePassword
- genshin.errors.InternalDatabaseError
- genshin.errors.OTPRateLimited
- RedemptionException
- genshin.errors.VerificationCodeRateLimited
- genshin.errors.VisitsTooFrequently
- genshin.errors.WrongOTP
Class variables
var msg : str
var original : str
var retcode : int
Instance variables
prop response : Mapping[str, Any]
-
Expand source code
@property def response(self) -> typing.Mapping[str, typing.Any]: return {"retcode": self.retcode, "message": self.original, "data": None}
class InvalidAuthkey (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class InvalidAuthkey(AuthkeyException): """Authkey is not valid.""" retcode = -100 msg = "Authkey is not valid."
Authkey is not valid.
Ancestors
- AuthkeyException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class InvalidCookies (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class InvalidCookies(CookieException): """Cookies weren't valid.""" retcode = -100 msg = "Cookies are not valid."
Cookies weren't valid.
Ancestors
- CookieException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class RedemptionClaimed (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class RedemptionClaimed(RedemptionException): """Redemption code has been claimed already.""" msg = "Redemption code has been claimed already."
Redemption code has been claimed already.
Ancestors
- RedemptionException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class RedemptionCooldown (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class RedemptionCooldown(RedemptionException): """Redemption is on cooldown.""" msg = "Redemption is on cooldown."
Redemption is on cooldown.
Ancestors
- RedemptionException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class RedemptionException (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class RedemptionException(GenshinException): """Exception caused by redeeming a code."""
Exception caused by redeeming a code.
Ancestors
- GenshinException
- builtins.Exception
- builtins.BaseException
Subclasses
Class variables
var msg : str
var original : str
var retcode : int
class RedemptionInvalid (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class RedemptionInvalid(RedemptionException): """Invalid redemption code.""" msg = "Invalid redemption code."
Invalid redemption code.
Ancestors
- RedemptionException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int
class TooManyRequests (response: Mapping[str, Any] | None = None, msg: str | None = None)
-
Expand source code
class TooManyRequests(CookieException): """Made too many requests and got ratelimited.""" retcode = 10101 msg = "Cannot get data for more than 30 accounts per cookie per day."
Made too many requests and got ratelimited.
Ancestors
- CookieException
- GenshinException
- builtins.Exception
- builtins.BaseException
Class variables
var msg : str
var original : str
var retcode : int