Check the EIA response before saving it as a workbook - #341
Open
arpitjain099 wants to merge 1 commit into
Open
arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
eia_7a_downloadwritesrequests.get(url).contentstraight tocoalpublic<year>.xlswithout looking at the status. When EIA answers 404, the error page gets saved as the workbook, andread_eia7alater raises the "see issues/230" ValueError. So a plain missing-file response is reported to the user as the XML-format problem from that issue, which is a different thing entirely.The folder was also created before the request, so after a failed download the caller's
if not os.path.exists(expected_7a_folder)guard stops trying andfind_file_in_folderfails on an empty directory instead.Now it calls
raise_for_status()first, only creates the folder and writes once the response is good, and the log line names the actual error.I checked both paths with
requests.getpatched: a 404 used to leave a 75-bytecoalpublic2016.xlsstarting<html><head><title>4, and now leaves nothing and logs "404 Not Found for url: ...". A 200 still writes the file as before.The except is now
except Exception as erather than bare, and the message is a warning rather than info, since a failed download does change what the rest of the run can do. Happy to drop that part if you would rather keep it quiet.