-
-
Save greatghoul/7352ba71134cf9079eb5e049c235cd64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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