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.72k stars 464 forks source link

Can't load pickled authentication #311

Closed qtcwt closed 3 years ago

qtcwt commented 3 years ago

Every time I tried to log in with pickle, it fails and prints ERROR: There was an issue loading pickle file. Authentication may be expired - logging in normally. No matter how long the login interval is.

By looking into the code, I found that this line of request_get(portfolio_profile_url(), 'regular', payload, jsonify_data=False) always returns 401, even immediately after I freshly log in successfully without a pickle file. I guess this API of getting portfolio profile is broken/inaccessible for my account/requiring additional verification?

My workaround for now is to get some other info, such as my position info, to verify if the session is still valid. I replaced the above line with request_get(positions_url(), 'pagination', {'nonzero': 'true'},jsonify_data=False).

fjehlik commented 3 years ago

Same issue here. I have to login twice and then it will load after sending an SMS authentication for a second time.

qtcwt commented 3 years ago

@fjehlik @AlgoTrader1234 Did you try my solution? If you could locate where robin_stocks is installed and replace this line of request_get(portfolio_profile_url(), 'regular', payload, jsonify_data=False) with request_get(positions_url(), 'pagination', {'nonzero': 'true'},jsonify_data=False), would the issue disappear?

I'm going to create a pull request later.

fjehlik commented 3 years ago

@qtcwt, thank you for the follow up. I am trying to find the robinstocks folder on my Mac to make the change (no luck finding where the pip install robin_stocks puts the package folder on the Mac yet so that the change can be made). Once that is figured out I will make the change and update~

fjehlik commented 3 years ago

@qtcwt, I found where the mac stores the authentication.py file, made the same change, rebooted Anaconda and logged in. I received the same error. However, like I before, if I log in a second time then it works (after the first pickle error).

qtcwt commented 3 years ago

@fjehlik I would suggest you to add one print around the changes to the authentication.py, just to make sure it's really using the changed code. If the change indeed takes effect but the same error remains, I guess the issue is somewhere else. I located my issue by debugging on vscode. You can set "justMyCode": false in launch.json and set a breakpoint in authentication.py to see what exactly goes wrong. Hope this helps.

qtcwt commented 3 years ago

@AlgoTrader1234 @fjehlik

When I was trying to configure the environment on a server, I realized that there can be two authentication.py in site-packages/robin_stocks. The one I've been referring to is site-packages/robin_stocks/robinhood/authentication.py, while there is another perhaps obsolete one site-packages/robin_stocks/authentication.py. Please double check you are changing the right one. On the other hand, like I shared in the last comment, you can verify whether your change really takes effect by adding one line of print to print out something random.

taziamoma commented 3 years ago

@qtcwt this worked for me! Thank you!

fjehlik commented 3 years ago

@qtcwt, thank you again for all the follow up it is greatly appreciated. I had changed the authentication.py file in the other folder, however, made the change you recommended and also included a print statement to verify it was the correct file. I still have the issue... it's more of a hassle than anything else as I can get it to work, I always just have to login a second time after getting the error and then the second time I enter the SMS code they send the second time it works.