robinhood-unofficial / pyrh

Python Framework to make trades with the unofficial Robinhood API
https://pyrh.readthedocs.io/en/latest/
MIT License
1.78k stars 603 forks source link

If a username (not email) is used for login and you attempt to load that session with 'pyrh.load_session()' ValidationError occurs #262

Closed clay-moss closed 4 years ago

clay-moss commented 4 years ago

Checklist

Description

If a username (not email) is used for login and you attempt to load that session with 'pyrh.load_session()' a ValidationError occurs

'marshmallow.fields' validation fails here: https://github.com/robinhood-unofficial/pyrh/blob/0113d31554fd707162743f3f1e8792efa1cc64ab/pyrh/models/sessionmanager.py#L522

Steps/Code to Reproduce

rh = load_session('.rh_session.json')

Example session JSON where issue would occur:

{
    "oauth": {
        "access_token": "xxxxx",
        "expires_in": 12345,
        "refresh_token": "xxxxx"
    },
    "username": "user123", 
    "device_token": "xxxxxx",
    "challenge_type": "email",
    "password": "password123",
    "expires_at": "2020-12-01"
}

Results

Traceback (most recent call last):
  File "C:/Users/Clayton/PycharmProjects/vix-pc-ratio-algo/algo.py", line 5, in <module>
    rh = load_session('.rh_session.json')
  File "C:\Users\Clayton\PycharmProjects\vix-pc-ratio-algo\venv\lib\site-packages\pyrh\cache.py", line 68, in load_session
    return cast(Robinhood, RobinhoodSchema().loads(file.read()))
  File "C:\Users\Clayton\PycharmProjects\vix-pc-ratio-algo\venv\lib\site-packages\marshmallow\schema.py", line 756, in loads
    return self.load(data, many=many, partial=partial, unknown=unknown)
  File "C:\Users\Clayton\PycharmProjects\vix-pc-ratio-algo\venv\lib\site-packages\marshmallow\schema.py", line 722, in load
    return self._do_load(
  File "C:\Users\Clayton\PycharmProjects\vix-pc-ratio-algo\venv\lib\site-packages\marshmallow\schema.py", line 904, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'username': ['Not a valid email address.']}   <---- email validation fails

Process finished with exit code 1

Versions

Windows-10-10.0.18362-SP0 Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] pyrh 2.0