robin_stocks icon indicating copy to clipboard operation
robin_stocks copied to clipboard

Mfa Code: Please enter a valid code

Open Ali-Riaz opened this issue 4 years ago • 4 comments

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('[email protected]','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.

Ali-Riaz avatar Aug 20 '20 04:08 Ali-Riaz

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.

jmfernandes avatar Aug 22 '20 23:08 jmfernandes

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.

Ali-Riaz avatar Aug 25 '20 05:08 Ali-Riaz

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

amudhanarun avatar Sep 13 '20 14:09 amudhanarun

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

ppkantorski avatar Jan 26 '21 02:01 ppkantorski