Closed realhitta closed 10 months ago
Same
Can you post your entire code? Without your credentials (username, password) of course 🙂.
Can you post your entire code? Without your credentials (username, password) of course 🙂.
I get the same error when I run the example code in the 'Quick Start' section.
from pyrh import Robinhood
rh = Robinhood(username="YOUR_EMAIL", password="YOUR_PASSWORD") rh.login()
Also having the same issue. Like @realhitta, just tried with a simple login() as the only code.
Having the same problem. Tried both from shell and from PyCharm. Tried with MFA and without.
File "venv\Lib\site-packages\pyrh\models\sessionmanager.py", line 162, in login self._login_oauth2() File "venv\Lib\site-packages\pyrh\models\sessionmanager.py", line 453, in _login_oauth2 raise AuthenticationError(msg) pyrh.exceptions.AuthenticationError: Method "GET" not allowed.
Adding my two cents here, for me this only happens when trying to run pyrh
within a Docker container. When running locally on my host machine, I am able to login fine. Doing some debugging/logging, I can see the following difference:
Note: I am using python version
3.11.4
and pyrh version2.1.2
Executing from my host machine:
(base) Andrews-MacBook-Pro-4:robinhood-trading-bot Andrew$ python rh-trading-bot.py
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.robinhood.com:443
DEBUG:urllib3.connectionpool:https://api.robinhood.com:443 "POST /oauth2/token/ HTTP/1.1" 200 None
Input mfa code:
Executing from within a Docker container:
(base) Andrews-MacBook-Pro-4:robinhood-trading-bot Andrew$ docker run -it sha256:0b924da9c28ad30fe7ee7e6a581081db0558d6f4b5a606bace0f289b60a07787
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.robinhood.com:443
DEBUG:urllib3.connectionpool:https://api.robinhood.com:443 "POST /oauth2/token HTTP/1.1" 301 0
DEBUG:urllib3.connectionpool:https://api.robinhood.com:443 "GET /oauth2/token/ HTTP/1.1" 405 40
Traceback (most recent call last):
File "/rh-trading-bot.py", line 7, in <module>
rh.login()
File "/usr/local/lib/python3.11/site-packages/pyrh/models/sessionmanager.py", line 162, in login
self._login_oauth2()
File "/usr/local/lib/python3.11/site-packages/pyrh/models/sessionmanager.py", line 453, in _login_oauth2
raise AuthenticationError(msg)
pyrh.exceptions.AuthenticationError: Method "GET" not allowed.
Seems like when executing within a Docker container, there is a 301
status code returned when trying to get a new oauth2 token, which represents a redirect response, and therefore the code tries to make a subsequent GET call which is erroneous.
Hmm following up, I was able to reproduce this on another laptop where I was unable to login even when on a local host machine. Most likely there is a dependency versioning issue somewhere.
Found the culprit (at least for me). For those affected, try downloading the specific yarl
package, which has to do with URL parsing: https://pypi.org/project/yarl/.
pip install yarl==1.8.2
I was able to get this working in a Docker container as well, if you're having trouble on your local host machine, you can check out my repo and try with the Docker container instead: https://github.com/Andrew5194/rh-trading-bot
That fixed the error for me. Thanks @Andrew5194
Description
FYI I'm not a coding expert by any means; just a hobbiest and casual investor.
anyone else getting this issue? I just tried the Quick Start code shown and I got the fllowing error:
File "C:\Users\Brian\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrh\models\sessionmanager.py", line 162, in login self._login_oauth2() File "C:\Users\Brian\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrh\models\sessionmanager.py", line 453, in _login_oauth2 raise AuthenticationError(msg) pyrh.exceptions.AuthenticationError: Method "GET" not allowed.