python-plexapi/tools/plex-gettoken.py
JonnyWong16 26447d1931
Add exception for two-factor required (#1357)
* Add exception for two-factor required

* Update tools/plex-gettoken.py with 2FA exception
2024-02-17 14:34:43 -08:00

19 lines
526 B
Python
Executable file

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Plex-GetToken is a simple method to retrieve a Plex account token.
"""
from getpass import getpass
from plexapi.exceptions import TwoFactorRequired
from plexapi.myplex import MyPlexAccount
username = input("Plex username: ")
password = getpass("Plex password: ")
try:
account = MyPlexAccount(username, password)
except TwoFactorRequired:
code = input("Plex 2FA code: ")
account = MyPlexAccount(username, password, code=code)
print(account.authenticationToken)