MicroPyramid / forex-python

Foreign exchange rates, Bitcoin price index and currency conversion using ratesapi.io
http://forex-python.readthedocs.io/en/latest/usage.html
MIT License
661 stars 195 forks source link

Stop waiting forever when "currency not ready" #136

Open soukun-kuno opened 1 year ago

soukun-kuno commented 1 year ago

the problem: when the url is down, the library waits just about forever for the response that's doomed to fail. i highly suspect this is the cause of all the "currency not ready" issues here. it could literarily be like a minute.

the fix: wait only 5 seconds instead. (this is just a random number i came up with. feel free to change it to something else that suits your need better.)

detailed explanation of why this is a good thing to do https://datagy.io/python-requests-timeouts/

Cruuncher commented 1 year ago

When adding a timeout you should be catching ReadTimeout and ConnectTimeout exceptions. Otherwise this is going to change the behaviour of the package. In the event of a timeout, the timeout exception will be thrown out of this function rather than the intended RatesNotAvailableError

Little bit of info on catching timeouts in requests: https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module

soukun-kuno commented 1 year ago

When adding a timeout you should be catching ReadTimeout and ConnectTimeout exceptions. Otherwise this is going to change the behaviour of the package. In the event of a timeout, the timeout exception will be thrown out of this function rather than the intended RatesNotAvailableError

Little bit of info on catching timeouts in requests: https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module

Thanks for the comment. Code modified to catch these exceptions and raise RatesNotAvailableError instead