robinhood-unofficial / pyrh

Python Framework to make trades with the unofficial Robinhood API
https://pyrh.readthedocs.io/en/latest/
MIT License
1.78k stars 603 forks source link

500 server error retries? #246

Closed emmeowzing closed 4 years ago

emmeowzing commented 4 years ago

Checklist

Feature Request

Just started using this, I'm building out a bit of a longer-term monitoring / calculation package on my portfolio. Every ~3-6 hours, I get 500 error-related tracebacks like

Traceback (most recent call last):
  File "./main.py", line 94, in <module>
    main()
  File "./main.py", line 58, in main
    today_close, prev_close, curr_val = th.total_dollar_equity()
  File "/home/brandon/projects/robinhood/stocks.py", line 54, in total_dollar_equity
    def total_dollar_equity(self) -> Tuple[float, float, float]:
  File "/home/brandon/anaconda3/envs/nvidia/lib/python3.7/site-packages/pyrh/robinhood.py", line 939, in equity_previous_close
    return float(self.portfolios()["equity_previous_close"])
  File "/home/brandon/anaconda3/envs/nvidia/lib/python3.7/site-packages/pyrh/robinhood.py", line 909, in portfolios
    req.raise_for_status()
  File "/home/brandon/anaconda3/envs/nvidia/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://api.robinhood.com/portfolios/

and I'm not sure if there's a way to simply retry the requests without decorating my methods, but then, I would also need to log in again as it kills my program without.

Perhaps this could be caught upstream?

emmeowzing commented 4 years ago

Could probably just close this out, but for others, wrote a decorator to retry (seems like a pretty standard way of handling this).