To use timeout I use requests in next mode:
import requests
r = requests.get(url, stream=True, timeout=2)
r.content()
BUT to use a size limit, I need to use stream:
import requests
r = requests.get(currentUrl,stream=True)
for chunk in r.iter_content(chunk_size=1024):
buffer.extend(chunk)
if len(buffer) > 1024 * 100:
r.close()
break
On streaming requests, the timeout only applies to the connection attempt. On regular requests, the timeout is applied to the connection process and on to all attempts to read data from the underlying socket. It does not apply to the total download time for the request.
Another option is to use Content-Length, but not all websites has this...
My question is how can I use both limitation in the same time? Or wich is suitable package for this?