csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
789 stars 171 forks source link

Support for max_retries when making call from requests #381

Closed Monal5031 closed 2 years ago

Monal5031 commented 3 years ago

I was using pyowm when I came across this error:

[ERROR] InvalidSSLCertificateError: HTTPSConnectionPool(host='api.openweathermap.org', port=443): 

Max retries exceeded with url: /data/2.5/weather?<ids> 

(Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1091)')))

After looking through the code I found there is no option in config to set a max_retries.

I was hoping this support could be added by allowing a max_retries param in any config and using it to create a new Session/Adapter for requests before making the API calls here:

https://github.com/csparpa/pyowm/blob/master/pyowm/commons/http_client.py#L131

csparpa commented 3 years ago

Good catch! Thanks, this will fit into the next release :)

Would you like to submit a PR yourself for this ?

Monal5031 commented 3 years ago

I can work on it @csparpa , although won't be able to complete it soon (I hope that's okay).

If someone else wishes to work on this, please let me know.

csparpa commented 2 years ago

Never mind @Monal5031 , I've submitted e3832d19b9c50bdb4bef9233899c0e85b2712e17 which should do the trick

By default, PyOWM will continue to apply infinite retries in calling the OWM API, but if you need to limit the number of calls this can be done via the configuration dict

By the way, in order to fix the InvalidSSLCertificateError you were getting, try to set "verify_ssl_certs": False in the config dict

Monal5031 commented 2 years ago

Thanks @csparpa for fixing the issue so fast and also for the suggestion I'll try that (I really don't want to disable SSL verification) :)