Skip to content

Commit d5f1d36

Browse files
author
Aaron Gonzales
committed
added exception handling around YAML file parsing
1 parent f845269 commit d5f1d36

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

twittersearch/api_utils.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,17 @@ def load_credentials(filename=None, account_type=None):
256256
with open(os.path.expanduser(filename)) as f:
257257
search_creds = yaml.load(f)["twitter_search_api"]
258258

259-
if account_type == "premium":
260-
search_args = {"bearer_token": search_creds["bearer_token"],
261-
"endpoint": search_creds["endpoint"]}
262-
if account_type == "enterprise":
263-
search_args = {"username": search_creds["username"],
264-
"password": search_creds["password"],
265-
"endpoint": search_creds["endpoint"]}
259+
try:
260+
261+
if account_type == "premium":
262+
search_args = {"bearer_token": search_creds["bearer_token"],
263+
"endpoint": search_creds["endpoint"]}
264+
if account_type == "enterprise":
265+
search_args = {"username": search_creds["username"],
266+
"password": search_creds["password"],
267+
"endpoint": search_creds["endpoint"]}
268+
except KeyError:
269+
logger.error("Your YAML file ({}) is not configured correctly and "
270+
" is missing a required field. Please see the "
271+
" readme for proper configuration".format(filename))
266272
return search_args

0 commit comments

Comments
 (0)