Add timeout argument to requests.(get,post)

This commit is contained in:
Jochen Sprickerhof 2022-09-05 17:15:15 +02:00
parent cf0100cf11
commit c89a9f0e8b
No known key found for this signature in database
GPG key ID: 5BFFDCC258E69433
11 changed files with 23 additions and 15 deletions

View file

@ -28,7 +28,9 @@ def download_file(url, local_filename=None, dldir='tmp'):
if local_filename is None:
local_filename = os.path.join(dldir, filename)
# the stream=True parameter keeps memory usage low
r = requests.get(url, stream=True, allow_redirects=True, headers=HEADERS)
r = requests.get(
url, stream=True, allow_redirects=True, headers=HEADERS, timeout=300
)
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):