-
Notifications
You must be signed in to change notification settings - Fork 486
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
KeyError on login #511
Comments
I am also having the same issue. I digged a little deeper. Seems like the return is some sort of verification issue. I have no idea how to fix this. |
have the same issue. Wondering if the API responses changed, but haven't had a chance to look into it at all yet. |
I have the same issue, unfortunately. It would be on a day where a stock is up 200%+. If anyone figures it out let me know! I'll take a look myself when I have the time. |
I am getting error message of unsupported_grant_type errors with a status code 403(had to modify my fork to get the error codes) #510 |
Getting the same error here, I used the otp code to see if it would work in robin and it seems to work fine. |
So you were able to verify the API or only that the OTP was working? |
@ravi-bharadwaj
I get error response of: |
@doormat-1010 I got the exact same error message. check out my comment. |
I was only able to veryify that the otp was working. |
anyone try it without an authenticator app 2FA enabled? Have a feeling that may be the issue.. but going to investigate tomorrow when I have time. |
I think the 2FA is mandatory in Robinhood now. |
@ahaggard2013 Yeah I'm thinking the structure has changed in the request somehow based on the error type. |
Is it possible the endpoint changed? |
If the structure of the request has changed, we should be able to use the DevTools network listener to view the new structure. I don't have time at the moment, but if anyone else does go for it! |
Alright, I've taken a look at it. Granted, I'm not the most experienced with this sort of thing but I've compared the payload sent by the browser to login to the one robin_stocks sends. It seems to me that the difference is that the payload used to include a header called mfa_code, but now the code may be received differently and is no longer a part of the same login request. When the browser sends the login payload even it receives the internal pending message which suggests to me that it's still waiting for the 2FA code to be entered. After that request, my machine sent a second payload consisting of my device_id, a value called flow and the workflow_id. Anyone have any ideas? |
Okay, yeah, there's a second payload sent titled "response" that contains the 2FA value once entered and submitted. Not sure if it can be included in the original login request, but it's being sent to a URL that I'm not sure how to use. It doesn't seem like it would be static. |
sounds like something changed. A few things, you could try the flow with device verification and sms verification instead of an authenticator. They may differ slightly and align with the current robin_stock flow. It's also likely the mobile api could use slightly different endpoints than the browser. You may have have to bypass certificate pinning to intercept robinhood mobile requests to compare them which can sometimes be tricky. The other option is modify the library to work with the new flow. A lot of work, but a few things I would like to try soon. not home so unable to debug atm |
Seems to me that we just have to whip up a new snippet that sends the mfa code to the new end-point under the "response" header. My lack of knowledge prevents me from quickly figuring out how to consistently have access to the correct end-point. |
There are two forks addressing it, has anyone checked them? |
Is it fixed ? not sure why, I reinstalled the robin_stocks and now it works |
I have not seen any commits to main and I tried on mine and it did not work |
When it fixed, were you using mfa? |
I am using mfa |
Could you check the version.. I updated to 3.2.1 and didnt work. |
it is 3.2.1 but I delete the original venv and create a new one to reinstall it. because I found pip uninstall will not remove old files in my machine |
I am fairly certain this is a Robinhood issue and not an issue with the python package since one of my accounts worked and one did not. Just my 2 cents On Dec 5, 2024, at 20:05, erchen7 ***@***.***> wrote:
it is 3.2.1 but I delete the original venv and create a new one to reinstall it. because I found pip uninstall will not remove old files in my machine
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Could it be an account configuration issue? |
seems like the flow has changed, first it calls token then pathfinder/user_machine and then user_view then you can call the /respond endpoint. I have been able to successfully call the /user_machine but its not working for /user_view |
I use R instead of Python, but it's all the same. I used the logic from above and rebuilt the login mechanism. you can see the code change here: altanalytics/RobinHood@bf41654 You shouldn't need to change anything on the Robinhood side. It just looks like they changed the authentication process and now require further levels of validation before logging you in. Good luck and let me know if you need any help. |
This is what I did, worked for me. |
I do appreciate everyone's input and effort and I do wish I was smart enough to contribute, but I am not. |
I have been working on my code for the last 2.5 years and have tried all your changes and have not come up successful. Current State: Still getting following error: |
it appears you have store_session=True. try setting it to false to skip the cached login and force a new login. |
Thank to all as well. This situation is a stretch beyond my knowledge. I as other have been putting in years on building a platform using this tool and have appreciated it so much. So I look forward when a fix can be merged. |
def td_rh_login(account): Is my final fix to the below solution: To get the device code. Log into RobinHood, account, settings, security and privacy, Two-Factor Authentication, then Authentication app -> select Update. You can add an account to MS Authentication app (verify method) and/or select can't read barcode to copy then paste in your python code (my case is bah_device = 'copied device code'
|
Is there any solution for the robinhood two factor authentication type -- Device approval ? .. I tried the above solution with the device approval authentication type, but getting the error 'status'.. |
For Anyone still troubleshooting: try this |
For those who are still having a problem, I recommend following the steps above using Ravi's authentification.py file, But the issue that I was having was I was pasting Ravi's authentification file into the wrong location. I was using some location where I downloaded the robinstock-API from git but not where my computer was pulling the git files which was from an old location I have used in the past. This true location is given in the error message when I try to run my script. That is the location where you want to paste Ravi's change. Also as for the authentification app, I am just using a text file where I pull the MFA code from and run it through python otp module. See this old video for how I do that: |
Is this the safest way to do authentication or is there something else I should research ? |
@gianpierre2024 |
I've tried several of the tips mentioned above over the past few days, but I'm still encountering the error message below. Could anyone kindly provide a solution that has worked for successfully logging in? I'm currently using version 3.2.1 of robin-stocks and have attempted to reset two-factor authentication using both text messages and an authenticator app. It will be highly appreciated. ERROR: There was an issue loading pickle file. Authentication may be expired - logging in normally. File ~\anaconda3\lib\site-packages\robin_stocks\robinhood\authentication.py:197, in login(username, password, expiresIn, scope, by_sms, store_session, mfa_code, pickle_path, pickle_name) KeyError: 'detail' |
Update: Thank you ravi-bharadwaj for the fix and thank you Tan-TanDesign for this: "take ravi's auth file and paste it into robin-stocks/robinhood/authentication.py. make sure it's the one inside the robinhood folder and not the one inside the robin-stocks folder." I feel so dumb I did not realized the right path to authentication.py, hope my mistake helps another lost soul out there. And finally, thanks to all for coming together and best wishes. |
Seems to me you are missing your 2FA, passing to the log in function just the username and password is for logging via SMS code, which I believe is no longer supported when using the API. Notes from my code: ==> [ (2) Factor Authentication. No need for Tx. Displays Current OTP ] <==totp = pyotp.TOTP(log_2FA).now() Hope it helps. |
Is there any solution that does not require manual authentication? Aka if I have someone enter there username and password it should auto login without having to set up some version of MFA, or is this the best we have for now? also when will these changes be merged? |
I would suggest, once you obtain your 2FA form robin, to just hardcode the 2FA, user_name and password; that way there is no need for human input to log in. |
if we can get the PR merged soon, it will avoid so much confusion and unnecesary steps that so many have to take. |
@Adelantado |
@Gates8911 Regarding the sleep, I would recommend to anyone to pause their program for a few secs after cancelling or submitting orders and check it's status; before doing anything else; I always do. There is no room in my logic for unconfirmed, rejected or failed orders so Ive learned to wait, check, and loop if necessary, Robinhood has gotten better and faster over time, but I've seen orders for up to two minutes with a status of "unconfirmed". Just my $0.02 |
@Adelantado I like the method you described do you have discord or some sort, where I could as you questions about the code I seem to still be struggling with your method |
I don't but you are welcome to email me anytime, if I can help, I will
On Monday, December 9, 2024 at 06:50:08 PM EST, SumayKalra ***@***.***> wrote:
@Adelantado I like the method you described do you have discord or some sort, where I could as you questions about the code I seem to still be struggling with your method
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@Adelantado Oh, when you said hardcoding I thought you meant your sensitive info is literally in the script itself, yeah as long as its masked some way it doesnt matter how you do it, i considered multiple strategies for this. Would certainly agree there is always different ways of accomplishing a task especially when it comes to coding, and yeah i also have my code check for the order status as well after a non interference sleep function, but i use a loop function with limited number of checks, and if the order isnt filled after all checks are ran it will simply cancel the order, I finally got a separate self update function to work as well, so if my script buys but then gets an error or for example I manually buy or sell one of the assets, the bot can update itself and store the necessary info to sell later or delete a position when sold. Not that this is relevant but i also found a python package recently that enables audio messages through voice assistance manipulation, so that your script can announce errors and other activities so that you dont need to be right there reading it to know what is happening, probably routine to a lot of people on this thread, but figured I would still throw it out there incase someone didnt know this exists. Also, what did you mean by you do not have room for unconfirmed etc.? And this may be a stupid question but again im self taught with full time job lol, so my knowledge is likely limited compared to most developers, the only reason i share my methods on here, is the off chance that someone else beginning their learning journey may stumble upon it an give em more ideas. |
@Gates8911 And once again....Thanks yall |
@Adelantado Assumed yall bounce ideas off eachother and what not as well, didnt mean to annoy anyone, have a good one. |
@Gates8911 .... All is cool. English is not my native language and I've been told more than once to come across as a bit hurst when expressing my thoughts. I am aware and I do apologize for it. |
anyone know how to make the code work for device approvals. i only get device approvals now from my iphone robinhood app. and then the code i run waits for the device approval to be approved and then checks to see if i can log in successfully. but it never sees that i approved the device. import random Generate a unique device tokendef generate_device_token():
Respond to challengesdef respond_to_challenge(challenge_id, sms_code): Save and load session datadef save_session(data, pickle_name="robinhood_session.pickle"): def load_session(pickle_name="robinhood_session.pickle"): def handle_verification_workflow(device_token, workflow_id):
def robinhood_login(username=None, password=None, expires_in=86400, scope="internal"):
Main flowif name == "main": Verification workflow triggered. Workflow ID: 00e60f42-de4c-4282-ad7d-e9c01a0206e1 |
When running the login protocol, I am getting a KeyError that shows this:
KeyError Traceback (most recent call last)
Cell In[6], line 3
1 import robin_stocks.robinhood as r
----> 3 login = r.login(username, password)
File ~/Library/jupyterlab-desktop/jlab_server/lib/python3.8/site-packages/robin_stocks/robinhood/authentication.py:190, in login(username, password, expiresIn, scope, by_sms, store_session, mfa_code, pickle_name)
185 pickle.dump({'token_type': data['token_type'],
186 'access_token': data['access_token'],
187 'refresh_token': data['refresh_token'],
188 'device_token': payload['device_token']}, f)
189 else:
--> 190 raise Exception(data['detail'])
191 else:
192 raise Exception('Error: Trouble connecting to robinhood API. Check internet connection.')
KeyError: 'detail'
The text was updated successfully, but these errors were encountered: