Skip to content

Commit

Permalink
Merge pull request #1751 from dandi/requests-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhelba authored Nov 29, 2023
2 parents d67632e + 226bcc6 commit 8bd133b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions dandiapi/api/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create_doi(version: Version) -> str:
settings.DANDI_DOI_API_USER,
settings.DANDI_DOI_API_PASSWORD,
),
timeout=30,
).raise_for_status()
except requests.exceptions.HTTPError as e:
logging.error('Failed to create DOI %s', doi)
Expand Down
8 changes: 4 additions & 4 deletions dandiapi/api/tests/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ def test_asset_download(api_client, storage, version, asset):
download_url = response.get('Location')
assert download_url == HTTP_URL_RE

download = requests.get(download_url)
download = requests.get(download_url, timeout=5)
cd_header = download.headers.get('Content-Disposition')

assert cd_header == f'attachment; filename="{os.path.basename(asset.path)}"'
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def test_asset_download_embargo(
download_url = response.get('Location')
assert download_url == HTTP_URL_RE

download = requests.get(download_url)
download = requests.get(download_url, timeout=5)
cd_header = download.headers.get('Content-Disposition')

assert cd_header == f'attachment; filename="{os.path.basename(asset.path)}"'
Expand Down Expand Up @@ -1427,7 +1427,7 @@ def test_asset_direct_download(api_client, storage, version, asset):
download_url = response.get('Location')
assert download_url == HTTP_URL_RE

download = requests.get(download_url)
download = requests.get(download_url, timeout=5)
cd_header = download.headers.get('Content-Disposition')

assert cd_header == f'attachment; filename="{os.path.basename(asset.path)}"'
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def test_asset_direct_download_head(api_client, storage, version, asset):
download_url = response.get('Location')
assert download_url == HTTP_URL_RE

download = requests.get(download_url)
download = requests.get(download_url, timeout=5)
cd_header = download.headers.get('Content-Disposition')

assert cd_header == f'attachment; filename="{os.path.basename(asset.path)}"'
Expand Down
12 changes: 8 additions & 4 deletions dandiapi/api/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def test_upload_initialize_and_complete(api_client, user, dandiset, content_size
transferred_parts = []
part_number = 1
for part in parts:
part_transfer = requests.put(part['upload_url'], data=b'X' * part['size'])
part_transfer = requests.put(part['upload_url'], data=b'X' * part['size'], timeout=5)
etag = part_transfer.headers['etag']
transferred_parts.append({'part_number': part_number, 'size': part['size'], 'etag': etag})
part_number += 1
Expand All @@ -403,7 +403,9 @@ def test_upload_initialize_and_complete(api_client, user, dandiset, content_size
).data

# Complete the upload to the object store
completion_response = requests.post(completion['complete_url'], data=completion['body'])
completion_response = requests.post(
completion['complete_url'], data=completion['body'], timeout=5
)
assert completion_response.status_code == 200

# Verify object was uploaded
Expand Down Expand Up @@ -442,7 +444,7 @@ def test_upload_initialize_and_complete_embargo(
transferred_parts = []
part_number = 1
for part in parts:
part_transfer = requests.put(part['upload_url'], data=b'X' * part['size'])
part_transfer = requests.put(part['upload_url'], data=b'X' * part['size'], timeout=5)
etag = part_transfer.headers['etag']
transferred_parts.append({'part_number': part_number, 'size': part['size'], 'etag': etag})
part_number += 1
Expand All @@ -457,7 +459,9 @@ def test_upload_initialize_and_complete_embargo(
).data

# Complete the upload to the object store
completion_response = requests.post(completion['complete_url'], data=completion['body'])
completion_response = requests.post(
completion['complete_url'], data=completion['body'], timeout=5
)
assert completion_response.status_code == 200

# Verify object was uploaded
Expand Down
6 changes: 4 additions & 2 deletions scripts/papertrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def cli(start, end, force, amend, output_file):

# Get archive list
headers = {'X-Papertrail-Token': PAPERTRAIL_TOKEN}
resp = requests.get('https://papertrailapp.com/api/v1/archives.json', headers=headers)
resp = requests.get(
'https://papertrailapp.com/api/v1/archives.json', headers=headers, timeout=30
)
if not resp.ok:
raise ClickException('Could not retrieve archive list')
archives: list[dict] = resp.json()
Expand Down Expand Up @@ -91,7 +93,7 @@ def cli(start, end, force, amend, output_file):
# Function to download an archive
def download_archive(archive: dict):
link = archive['_links']['download']['href']
resp = requests.get(link, headers=headers, stream=True)
resp = requests.get(link, headers=headers, timeout=30, stream=True)
with output_file.open('ab') as outfile:
outfile.write(resp.raw.read())

Expand Down

0 comments on commit 8bd133b

Please sign in to comment.