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

pyfetch: Do not raise an error on status code >= 400 #3986

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ myst:
`pyodide-lock.json`
{pr}`3824`

- {{ Breaking }} Changed the FetchResponse body getter methods to no longer
throw an OSError exception for 400 and above response status codes
{pr}`3986`

### Packages

- OpenBLAS has been added and scipy now uses OpenBLAS rather than CLAPACK
Expand Down
4 changes: 0 additions & 4 deletions src/py/pyodide/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def url(self) -> str:
return self.js_response.url

def _raise_if_failed(self) -> None:
if self.js_response.status >= 400:
raise OSError(
f"Request for {self._url} failed with status {self.status}: {self.status_text}"
)
if self.js_response.bodyUsed:
raise OSError("Response body is already used")

Expand Down
20 changes: 20 additions & 0 deletions src/tests/test_pyodide_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from pytest_pyodide import run_in_pyodide


@pytest.fixture
def url_notfound(httpserver):
httpserver.expect_request("/data").respond_with_data(
b"404 Not Found",
content_type="text/text",
headers={"Access-Control-Allow-Origin": "*"},
status=404,
)
return httpserver.url_for("/data")


@pytest.mark.xfail_browsers(node="XMLHttpRequest is not available in node")
def test_open_url(selenium, httpserver):
httpserver.expect_request("/data").respond_with_data(
Expand Down Expand Up @@ -34,6 +45,15 @@ async def test_pyfetch_create_file(selenium):
)


@run_in_pyodide
async def test_pyfetch_return_400_status_body(selenium, url_notfound):
from pyodide.http import pyfetch

resp = await pyfetch(url_notfound)
body = await resp.string()
assert body == "404 Not Found"


@run_in_pyodide
async def test_pyfetch_unpack_archive(selenium):
import pathlib
Expand Down