davidhuser / dhis2.py

Generic and lightweight Python wrapper for the DHIS2 API using requests
MIT License
15 stars 11 forks source link

Timeouts #15

Closed davidhuser closed 3 years ago

davidhuser commented 4 years ago

implement optional parameter for https://requests.readthedocs.io/en/master/user/quickstart/#timeouts

You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely.

at https://github.com/davidhuser/dhis2.py/blob/master/dhis2/api.py#L202

davidhuser commented 3 years ago

Implemented in v2.2.0 with a default of 5 seconds, and in v2.2.1 with a no default value again.

Nearly all production code should use this parameter in nearly all requests.

If you face errors such as:

requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='play.dhis2.org/demo', port=443): Read timed out. (read timeout=5)

You can improve your code by setting your own appropriate timeout values by overwriting the timeout parameter in seconds:

from dhis2 import Api

api = Api('play.dhis2.org/demo', 'admin', 'district')
r = api.get('endPoint', timeout=60) # <-- see here
data = r.json()