sshh12 / Tradinhood

Programmatically trading stocks, crypto, and options with Robinhood.
MIT License
22 stars 9 forks source link

400 error at login #9

Closed alexonab closed 5 years ago

alexonab commented 5 years ago

I'm new to this repo and am unable to get passed the login.

$ python3 Python 3.7.4 (default, Jul 11 2019, 10:43:21) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import config from tradinhood import Robinhood rbh = Robinhood() rbh.login(username=config.robinhood_username, password=config.robinhood_password) Traceback (most recent call last): File "/tmp/rh/lib/python3.7/site-packages/tradinhood/robinhood.py", line 167, in login res.raise_for_status() File "/tmp/rh/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.robinhood.com/oauth2/token/

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/tmp/rh/lib/python3.7/site-packages/tradinhood/robinhood.py", line 170, in login raise APIError('Login failed') tradinhood.robinhood.APIError: Login failed

sshh12 commented 5 years ago
sshh12 commented 5 years ago

Looks like the Robinhood login API changed slightly, I'll see if I can patch it.

If you want to login in the meantime, login with your browser at robinhood.com and find the Authorization header that's being sent. Then use rbh.login(token="...").

sshh12 commented 5 years ago

Should be fixed in v0.2.2.

alexonab commented 5 years ago

I have updated to 0.2.2 and the 400 error remains. I suspect it's due to the forced sms/email code that RH requires at login. I have switched to using the token option mentioned above. FWIW, another lib is working through the 400 error also and seem to have partially resolved it. https://github.com/westonplatter/fast_arrow_auth

sshh12 commented 5 years ago

Ugh, yeah it looks like this is it:

fast_arrow_auth/client.py#L150

I've been using codes from Google Authenticator which I guess bypasses this. I'll try to implement a similar challenge handler as the one linked and post it here.

sshh12 commented 5 years ago

I updated v0.2.2 to include the code for challenge verification and confirmed it worked on my account when MFA was disabled.