Skip to content

Commit

Permalink
fix #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Jan 16, 2022
1 parent 3283e1e commit a379574
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions twspace_dl/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a379574

Please sign in to comment.