-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to login anymore - firstly got reported as pickle is invalid #524
Comments
I used the authenticator App and the latest robin_stock code and that looks to have solved the issue import os
import pyotp
import argparse
import robin_stocks.robinhood as r
def generate_token():
totp = pyotp.TOTP("My2factorAppHere").now()
print(f"TOTP: {totp}")
def login(mfa_code):
username = os.getenv("RH_USERNAME")
password = os.getenv("RH_PASSWORD")
if not username or not password:
print("Error: RH_USERNAME or RH_PASSWORD environment variables are not set.")
exit(1)
# Add your login logic here
print(f"User parameter: {mfa_code}")
login = r.login(username, password, mfa_code=mfa_code)
print(f"Login: {login}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process command line arguments.")
parser.add_argument("action", choices=["token", "login"], help="Action to perform: 'token' or 'login'")
parser.add_argument("mfa_code", nargs='?', help="User parameter for login action")
args = parser.parse_args()
if args.action == "token":
generate_token()
elif args.action == "login":
if args.mfa_code:
login(args.mfa_code)
else:
print("Error: user_param is required for login action.")
exit(1) |
Latest robin-stocks code? I used the code below with the latest release plus the authentication.py module from two weeks ago with the sheriff module and it no longer works for me. It doesn't prompt me for the MFA code, it just errors out. import robin_stocks.robinhood now = datetime.now() |
have you set up an authenticator app?
In your login enter the MFA code login = r.login(username, password, mfa_code=mfa_code_from_authenticator_of_robinhood) This will store a |
I guess I'm just dumb because i have been trying for two days wit this script and no success,import os def generate_token(): def login(mfa_code): if name == "main":
|
@nat2k5us , thanks for responding. Yes, I am passing the mfa code (see my updated code above). If you look at the attachment, that is where everything goes wrong in authentication.py. Right below the blue line in the attached file is: if 'mfa_required' in data: This broke for me two weeks ago. I loaded the new authentication.py file with the sheriff module and that fixed it. Now it's broken again. |
Can you try it on this repo - I will try and backup my pickle file and try again to login as well also, the the msft authenticator app is what I am using - I remove the old Robinhood and re-added it again with a new code run the ./run-login-test.sh |
It worked (in the repo I shared) after I deleted the .pickle.robinhood and tried the login again - Firstly ensure your correct username and password are present in the env
- make sure you give enough time for the mfa_code
./run-login-test.sh login mfa_code_from_authenticator_app
After that you can use
./run-login-test.sh login totp |
Here’s a code snippet that fixes the issues and works with MFA + the updated client ID: import os
import requests
import pyotp
def login_robinhood():
"""
Logs into Robinhood using TOTP-based 2FA.
Make sure RH_USERNAME, RH_PASSWORD, and RH_2FA_SECRET are set as environment variables.
"""
# Get credentials from environment variables
username = os.getenv("RH_USERNAME")
password = os.getenv("RH_PASSWORD")
totp_secret = os.getenv("RH_2FA_SECRET") # Your authenticator app's secret
if not username or not password or not totp_secret:
print("Error: Missing RH_USERNAME, RH_PASSWORD, or RH_2FA_SECRET environment variable.")
return None
# Generate the TOTP code
totp = pyotp.TOTP(totp_secret).now()
print(f"Generated TOTP: {totp}")
# API endpoint and payload
url = "https://api.robinhood.com/oauth2/token/"
payload = {
"username": username,
"password": password,
"mfa_code": totp,
"grant_type": "password",
"scope": "internal",
"client_id": "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS", # Latest client ID
}
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
}
try:
response = requests.post(url, data=payload, headers=headers)
response.raise_for_status()
data = response.json()
if "access_token" in data:
print("Login successful!")
return data
else:
print("Login failed. Response:", data)
return None
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error: {http_err}")
if response.text:
print("Response text:", response.text)
except Exception as e:
print(f"An error occurred: {e}")
return None
if __name__ == "__main__":
token = login_robinhood()
if token:
print("Access Token:", token["access_token"])
else:
print("Failed to log in to Robinhood.") Why This Works:
Next Steps:
|
i got this error back,Traceback (most recent call last): |
now i'm getting back this error, HTTP error: 400 Client Error: Bad Request for url: https://api.robinhood.com/oauth2/token/ |
Any success with this? I am experiencing the same problem, I am providing the correct MFA code and updated to latest verison of the repo, still fall into the state 'workflow_status_internal_pending' inside _validate_sherrif_id method ... *** Edit: ok stupid error on my side: when you update the MSA app key, remember to validate it by going back to RH app and tapping 'Continue' at the bottom of the screen. You'll be prompted the Auth app current code. This step is needed to make sure the app validates the correct setup of your MFA key. It works now for me. |
Unable to login anymore - firstly got reported as pickle is invalid
Then after many attempts still not able to get past the key error when using the simple login method
I have 2FA enabled with the authenticator app - so when the login/pikle has expired I would get prompted to enter the authenticator app code in the console - but now that is no longer is happening
The client id is being reported as invalid - is there a new client id - how to get a valid id?
Thank you
got these error
File "/Users/xxxxxx/dev/rh/myprofits/libs/robin_stocks/robin_stocks/robinhood/authentication.py", line 190, in login
raise Exception(data['detail'])
Exception: Unable to log in with provided credentials.
The text was updated successfully, but these errors were encountered: