SHARE
TWEET

Untitled

a guest Jun 25th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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'))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top