pyrh: Login Errors with 2FA (email code)

Checklist

  • [ x] I am on the latest pyrh version.
  • [ x] I have searched the issues of this repo and believe that this is not a duplicate.

Description

Getting an error when trying to log in following instructions on quickstart, prompts for a 2FA email code and I enter the SMS code which fails to work

Steps/Code to Reproduce

import config

robinhood = Robinhood()

robinhood.login(username= config.username, password= config.password)

quote = robinhood.quote_data("TWTR")

print(quote)

Results

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyrh/robinhood.py", line 215, in login
    res2.raise_for_status()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.robinhood.com/challenge//respond/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "trade.py", line 6, in <module>
    robinhood.login(username= config.username, password= config.password)
  File "/usr/local/lib/python3.7/site-packages/pyrh/robinhood.py", line 228, in login
    raise RH_exception.LoginFailed()
pyrh.exceptions.LoginFailed

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 30 (2 by maintainers)

Most upvoted comments

Ok, I think I figured out the issue! 🎉

In the constructor for Robinhood.login() there is a keyword argument challenge_type. The default is email. Change this to whatever 2FA format you prefer. I’m not sure what all the available options are (not really documented anywhere) but I changed mine to sms and it worked.

Here’s an example below.

import os
from pyrh import Robinhood

USERNAME = os.getenv('ROBINHOOD_USERNAME')
PASSWORD = os.getenv('ROBINHOOD_PASSWORD')

rh = Robinhood()
rh.login(username=USERNAME, password=PASSWORD, challenge_type='sms')

You should receive your 2FA code via SMS - enter it and it should return True.

Note I don’t have 2FA turned on in my Robinhood app settings.

Hope this helps!

Sorry everyone for leaving y’all hanging! I’ve been busy lately with other projects. I’ll do more research into this

Sorry everyone for leaving y’all hanging! I’ve been busy lately with other projects. I’ll do more research into this

Yo @Jamonek – The latest PYPI release is just old – you can re-release it should fix the issues. Thanks so much!! This is an awesome project!

@alexandrepdumont done, check https://github.com/HenryFBP/robinhoodtest. It should work finally…

I hope the maintainers of this package see this thread and decide to finally make a new release, or automate their releases…I may end up doing that myself if this proves useful for stock trading and then just submit a pull request.

Haha, so this stupid idiot (me) spent 1 hour re-releasing an old Python OSS project into PyPI, but didn’t know that Robin Hood changed their backend APIs too, and now all the pagination/data structures are different…and has to either find a new library or rewrite their rest api backend

Yes…let’s hope not XD

Anyways, Poetry can pull from PyPI (poetry add pyrhhfbp) or using Git URLs. Check the pyproject.toml file for how to do either.

@alexandrepdumont I am working on releasing the latest build of pyrh to PyPI – check https://github.com/HenryFBP/robinhoodtest/blob/master/pyproject.toml line 10 for the new version, I am about to upload it

You sir are a coding genius I’ll try this latest solution and get back to you.

On Sun, Apr 17, 2022, 11:37 Henry Post @.***> wrote:

I just realized…The latest version of pyrh on PyPI seems to be outdated. The constructor I get when installing pyrh==2.0 looks like this:

class Robinhood: “”“Wrapper class for fetching/parsing Robinhood endpoints “””

session = None
username = None
password = None
headers = None
auth_token = None
refresh_token = None

but the master branch, which works with the “working code” I put above, looks like this:

class Robinhood(InstrumentManager, SessionManager): “”“Wrapper class for fetching/parsing Robinhood endpoints. Please see :py:class:SessionManager for login functionality. Provides a global convenience wrapper for the following manager objects: * InstrumentManager * TODO: Add to this list “””

— Reply to this email directly, view it on GitHub https://github.com/robinhood-unofficial/pyrh/issues/251#issuecomment-1100902950, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFHTBSV3AAHJ7GXLUTLFQDVFQV3RANCNFSM4NMR2M6A . You are receiving this because you were mentioned.Message ID: @.***>