Skip to content

Instantly share code, notes, and snippets.

@greatghoul
Created September 15, 2016 09:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greatghoul/7352ba71134cf9079eb5e049c235cd64 to your computer and use it in GitHub Desktop.
Save greatghoul/7352ba71134cf9079eb5e049c235cd64 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import requests
import time
max_timeout = 10
max_buffer_size = 1024 * 1024
r = requests.get('http://localhost:8888', stream=True, timeout=max_timeout)
r.raise_for_status()
size = 0
start = time.time()
for chunk in r.iter_content(1024):
if time.time() - start > max_timeout:
raise ValueError('timeout reached')
size += len(chunk)
if size > max_buffer_size:
print max_buffer_size
raise ValueError('response too large')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment