jmfernandes / robin_stocks

This is a library to use with Robinhood Financial App. It currently supports trading crypto-currencies, options, and stocks. In addition, it can be used to get real time ticker information, assess the performance of your portfolio, and can also get tax documents, total dividends paid, and more. More info at
http://www.robin-stocks.com
MIT License
1.74k stars 468 forks source link

Mfa Code: Please enter a valid code #156

Open Ali-Riaz opened 4 years ago

Ali-Riaz commented 4 years ago

Hi everyone!

I'm not sure if anyone else is facing this issue or maybe I'm doing this incorrectly but thought I'd raise it. I can use the basic login (without 2F-Authentication) just fine but I'm running into trouble when trying to log in via 2F-Authentication.

I'm using Pycharm editor, Python version 3.8 and have already installed the robin_stocks and pyotp modules.

Here's what I have done so far: 1) Searched Google for the issue. 2) Looked through similar or related questions already raised by the community members. 3) Setup 2F-Authentication on my phone using Google Authenticator, currently enabled. 4) Using the same alpha-numeric code that I manually entered in Google Authenticator.

My code is as follows:

import pyotp
import robin_stocks as r

totp = pyotp.TOTP("Same alpha-numeric code entered manually in Google Authenticator").now()
print("Current OTP:", totp)
login = r.login('someone@mail.com','NotSoSecurePassword', mfa_code=totp, expiresIn=120)

When I run the above code, the following exception is raised: "Please enter a valid code". Any insights would be greatly appreciated.

jmfernandes commented 4 years ago

try opening robinhood phone app and when it asks for MFA code, run the code above so it prints out the current OTP. Then manually type that number into your phone app to see if it accepts it. Let me know what happens.

I believe what you did should work, but just so you know when i set up MFA on robinhood, i clicked "other" instead of telling it to use google authenticator. I then added the alphanumeric code to my python code to generate the MFA to complete set up. After that, is when i manually set up google authenticator with the same code.

Ali-Riaz commented 4 years ago

Hey Joshua!

Yes, I tried it exactly the way you mentioned but I'm still getting the same error: Mfa code: Please enter a valid code. I had to work with Google Authenticator because for whatever reason the code generated from pyotp wasn't being accepted in the Robinhood app. Does it work in your case? Trying to understand if anyone else has encountered this issue.

amudhanarun commented 4 years ago

Hello,

I am getting the same error. when i put in the otp in the mobile app, I am getting the error : Please enter a valid code

ppkantorski commented 3 years ago

I couldnt get automatic MFA verification like descriibed in the recent update.. instead I made a workaround with Twilio to handle the MFA sms.