Skip to content

FIX: fetch_nb_dependencies must not save HTTP error pages - #904

Open
Sanjays2402 wants to merge 1 commit into
QuantEcon:mainfrom
Sanjays2402:fix/fetch-nb-dependencies-http-errors
Open

FIX: fetch_nb_dependencies must not save HTTP error pages#904
Sanjays2402 wants to merge 1 commit into
QuantEcon:mainfrom
Sanjays2402:fix/fetch-nb-dependencies-http-errors

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #870

fetch_nb_dependencies wrote whatever the server returned straight to disk and appended True to the status list, so requesting a file that does not exist remotely saved GitHub's HTML error page under the requested filename and reported it as fetched — surfacing later as a parse error in unrelated code.

This calls raise_for_status() and appends False on any RequestException instead of writing the body, adds a default request timeout (overridable by keyword), stops rebinding the loop variable to the open file handle, and accepts a tuple via isinstance rather than type(files) == list.

Three regression tests in TestFetchNbDependenciesErrors cover the three behaviours; all three fail against the original source (error page written, timeout rejected as an unexpected kwarg, tuple raising AttributeError: 'tuple' object has no attribute 'keys') and pass with the fix. The two existing network tests are untouched.

fetch_nb_dependencies wrote whatever the server returned straight to
disk and appended True to the status list, so a request for a missing
remote file saved GitHub's HTML error page under the requested
filename and reported it as fetched. The failure only surfaced later
as a parse error in unrelated code.

- call raise_for_status() and append False on any RequestException
  instead of writing the response body
- add a default request timeout, overridable via the timeout keyword
- stop rebinding the loop variable to the open file handle
- accept a tuple of filenames via isinstance instead of type(..) == list

Closes QuantEcon#870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FIX: fetch_nb_dependencies writes HTTP error pages to disk and reports success

1 participant