Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Error when HTTPReader get 404 Response (#160) #569

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/test_remote_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def test_http_reader_iterdatapipe(self):

# __len__ Test: returns the length of source DataPipe
self.assertEqual(1, len(http_reader_dp))

# Error Test: test if the Http Reader raises an error when the url is invalid
error_url = "https://github.com/pytorch/data/this/url/dont/exist"
http_error_dp = HttpReader(IterableWrapper([error_url]), timeout=timeout)
with self.assertRaises(Exception) as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assertRaisesRegex it will reduce lines 91-92 to simple check.

next(iter(http_error_dp.readlines()))
err_msg = "Could not get the file. [HTTP Error] <Response [404]>."
self.assertEqual( str(e.exception)[:54], err_msg)

def test_on_disk_cache_holder_iterdatapipe(self):
tar_file_url = "https://raw.githubusercontent.com/pytorch/data/main/test/_fakedata/csv.tar.gz"
Expand Down
1 change: 1 addition & 0 deletions torchdata/datapipes/iter/load/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _get_response_from_http(
r = session.get(url, stream=True, proxies=proxies, **query_params) # type: ignore[arg-type]
else:
r = session.get(url, timeout=timeout, stream=True, proxies=proxies, **query_params) # type: ignore[arg-type]
r.raise_for_status()
return url, StreamWrapper(r.raw)
except HTTPError as e:
raise Exception(f"Could not get the file. [HTTP Error] {e.response}.")
Expand Down