feat: meaningful error message for bad credentials

pull/1138/head
Callum Leslie 3 years ago
parent 66ec9b34d2
commit 71c317da23
No known key found for this signature in database
GPG Key ID: D382C4AFEECEAA90

@ -1,5 +1,7 @@
import re import re
from prawcore.exceptions import ResponseException
from utils import settings from utils import settings
import praw import praw
from praw.models import MoreComments from praw.models import MoreComments
@ -29,14 +31,21 @@ def get_subreddit_threads(POST_ID: str):
username = settings.config["reddit"]["creds"]["username"] username = settings.config["reddit"]["creds"]["username"]
if str(username).casefold().startswith("u/"): if str(username).casefold().startswith("u/"):
username = username[2:] username = username[2:]
reddit = praw.Reddit( try:
client_id=settings.config["reddit"]["creds"]["client_id"], reddit = praw.Reddit(
client_secret=settings.config["reddit"]["creds"]["client_secret"], client_id=settings.config["reddit"]["creds"]["client_id"],
user_agent="Accessing Reddit threads", client_secret=settings.config["reddit"]["creds"]["client_secret"],
username=username, user_agent="Accessing Reddit threads",
passkey=passkey, username=username,
check_for_async=False, passkey=passkey,
) check_for_async=False,
)
except ResponseException as e:
match e.response.status_code:
case 401:
print("Invalid credentials - please check them in config.toml")
except:
print("Something went wrong...")
# Ask user for subreddit input # Ask user for subreddit input
print_step("Getting subreddit threads...") print_step("Getting subreddit threads...")

Loading…
Cancel
Save