robinhood-unofficial / pyrh

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

marshmallow.exceptions.ValidationError: {'challenge': {'type': ['Must be one of: email, sms.']}} #305

Closed akibnizam closed 1 year ago

akibnizam commented 1 year ago

I have the following lines -

RH = Robinhood(username="email@email.com", password="xxxxxx", challenge_type="sms")
RH.login()

And then I get the following error ->

RH.login()
  File "/usr/local/lib/python3.10/site-packages/pyrh/models/sessionmanager.py", line 162, in login
    self._login_oauth2()
  File "/usr/local/lib/python3.10/site-packages/pyrh/models/sessionmanager.py", line 433, in _login_oauth2
    oauth = self.post(
  File "/usr/local/lib/python3.10/site-packages/pyrh/models/sessionmanager.py", line 290, in post
    data = res.json() if schema is None else schema.load(res.json(), many=many)
  File "/usr/local/lib/python3.10/site-packages/marshmallow/schema.py", line 722, in load
    return self._do_load(
  File "/usr/local/lib/python3.10/site-packages/marshmallow/schema.py", line 909, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'challenge': {'type': ['Must be one of: email, sms.']}}

Is there something I am missing?

adithyabsk commented 1 year ago

Can you tell me which version of the package you are using?

>>>  import pyrh
>>> pyrh.__version__
akibnizam commented 1 year ago

@adithyabsk thanks for getting back so quickly!

It is '2.0.1'

adithyabsk commented 1 year ago

That's really strange--don't seem to be having that issue on my end. Just pushed the latest code to pypi so I'd be able to better debug, can you downloaded the latest version of the package 2.1.1?

akibnizam commented 1 year ago

Reinstalled latest version but still same error :/

I get the following notification on the app to verify if it is me trying to access since i have "Device approvals" under 2FA ->

image

image

adithyabsk commented 1 year ago

yeah not sure. maybe it has something to do with your locale, and the return code from robinhood. If you install the project from source and throw a breakpoint import pdb; pdb.set_trace() before marshmallow does the deserialization, we might be able to figure out more about what's going wrong. Specifically, before line 290 in your error traceback.

akibnizam commented 1 year ago

Gotcha! I will do the debugging

akibnizam commented 1 year ago

So I looked at the issue before line 290 in sessionmanager.py and seems like after sending post request in at 273 I am getting response -

b'{"detail":"Request blocked, prompt challenge issued.","challenge":{"id":"_random id here_","user":"eaxxxxxxx","type":"prompt","alternate_type":"sms","status":"issued","remaining_retries":3,"remaining_attempts":1,"expires_at":"2023-01-24T02:54:56.445001-05:00","updated_at":"2023-01-24T02:49:56.445342-05:00","flow_id":"login","mfa_status":"prompt","silent":false,"silent_factor_id":null}}'

akibnizam commented 1 year ago

Issue resolved! The problem was that I had "device approval" option enabled for 2FA and so everytime I was accessing through api, RH was asking a trusted device (my phone) for approval but by that time the request is denied to my api.

Solved it by changing to text based 2FA or 3rd party authenticator.

adithyabsk commented 1 year ago

@akibnizam glad it's resolved. If you have the time it would be great to throw up a quick PR to catch this error and display a more meaningful error code. (ie parse the additional response type from Robinhood and say it's not supported)

akibnizam commented 1 year ago

@adithyabsk sounds good! I will make a PR related to it