First off, thanks for putting this script together! Will save me a lot of time.
When running csv-export.py without any prior configuration, I got a KeyError:
$ python csv-export.py
Traceback (most recent call last):
File "csv-export.py", line 53, in <module>
if logged_in != True and logged_in.get('non_field_errors') == None and logged_in['mfa_required'] == True:
KeyError: 'mfa_required'
This is because os.getenv returns None as a default value, overwriting the "" value we had from argparse, meaning we never get to the interactive username/password prompt and instead call robinhood.login with None as username and password. login returns the Robinhood response to this which is:
{u'detail': u'Unable to log in with provided credentials.'}
which in turn leads us to throw a KeyError because we assume there is a mfa_required key if there are no non_field_errors in the RH response.
This change ensures that we prompt for username/password when they're not provided in arguments or envvars, and stops the KeyError from occurring when the RH response doesn't contain a mfa_required key.
First off, thanks for putting this script together! Will save me a lot of time.
When running
csv-export.py
without any prior configuration, I got aKeyError
:This is because
os.getenv
returnsNone
as a default value, overwriting the""
value we had fromargparse
, meaning we never get to the interactive username/password prompt and instead callrobinhood.login
withNone
as username and password.login
returns the Robinhood response to this which is:which in turn leads us to throw a
KeyError
because we assume there is amfa_required
key if there are nonon_field_errors
in the RH response.This change ensures that we prompt for username/password when they're not provided in arguments or envvars, and stops the
KeyError
from occurring when the RH response doesn't contain amfa_required
key.