Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import requests
  2. import urllib3
  3. from retry import retry
  4.  
  5. def download(url):
  6.  
  7. @retry((requests.exceptions.RequestException, urllib3.exceptions.HTTPError), tries=3, delay=3)
  8. def _make_request(url):
  9. response = requests.get(url)
  10. response.raise_for_status()
  11. return response
  12.  
  13. response = _make_request(url)
  14.  
  15. for chunk in response.iter_content(chunk_size=32 * 1024):
  16. yield chunk
  17.  
  18. result = list(download('http://httpstat.us/500'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement