diff --git a/twspace_dl/login.py b/twspace_dl/login.py index bdd0500..ecee3a1 100644 --- a/twspace_dl/login.py +++ b/twspace_dl/login.py @@ -6,9 +6,18 @@ def load_from_file(filename: str) -> str: """return auth_token from netscape cookie file""" - return re.findall( - r"(?<=auth_token\s)\w{40}", open(filename, "r", encoding="utf-8").read() - )[0] + try: + token = re.findall( + r"(?<=auth_token\s)\w{40}", open(filename, "r", encoding="utf-8").read() + )[0] + except IndexError as err: + raise ValueError( + ( + "Cookie file does not have auth_token.\n" + "Please check if you were connected when creating it" + ) + ) from err + return token def write_to_file(auth_token: str, filename: str) -> None: