Skip to content

Commit

Permalink
Fix blank slate crash (#42)
Browse files Browse the repository at this point in the history
* Default to empty string if username/pw not in env

This ensures we prompt for username and password if they are not present in
arguments or in envvars (os.getenv defaults to None, not "")

* Prevent KeyError if providing empty username/password
  • Loading branch information
martinmelin authored and joshfraser committed Mar 5, 2019
1 parent a789918 commit e8e5cf4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions csv-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
while logged_in != True:

if username == "":
username = os.getenv("RH_USERNAME")
username = os.getenv("RH_USERNAME", "")
if username == "":
print("Robinhood username:", end=' ')
try:
Expand All @@ -45,12 +45,12 @@
username = input()

if password == "":
password = os.getenv("RH_PASSWORD")
password = os.getenv("RH_PASSWORD", "")
if password == "":
password = getpass.getpass()

logged_in = robinhood.login(username=username, password=password)
if logged_in != True and logged_in.get('non_field_errors') == None and logged_in['mfa_required'] == True:
if logged_in != True and logged_in.get('non_field_errors') == None and logged_in.get('mfa_required') == True:

if mfa_code is None:
mfa_code = os.getenv("RH_MFA")
Expand Down

0 comments on commit e8e5cf4

Please sign in to comment.