You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2, because the changes are localized to a specific method and involve standard Python libraries. The logic is straightforward and the modifications are minimal, making it relatively easy to review.
🧪 Relevant tests
No
⚡ Possible issues
Possible Bug: The PR does not handle exceptions that may occur during file operations or zip file extraction. It would be beneficial to add error handling to manage scenarios where file writing or extraction fails.
-with tempfile.TemporaryDirectory() as tmp_dir:- zip_file = os.path.join(tmp_dir, file_name + ".zip")- with open(zip_file, "wb") as file:- file.write(base64.b64decode(contents))+try:+ with tempfile.TemporaryDirectory() as tmp_dir:+ zip_file = os.path.join(tmp_dir, file_name + ".zip")+ with open(zip_file, "wb") as file:+ file.write(base64.b64decode(contents))- with zipfile.ZipFile(zip_file, "r") as zip_ref:- zip_ref.extractall(target_directory)+ with zipfile.ZipFile(zip_file, "r") as zip_ref:+ zip_ref.extractall(target_directory)+except Exception as e:+ logging.error(f"Failed to download and extract file {file_name}: {e}")
Suggestion importance[1-10]: 8
Why: Adding error handling would significantly improve the robustness of the file handling operations, making the code safer and more reliable.
8
Possible issue
Ensure the target directory exists before extracting files
Ensure that the target_directory exists before attempting to extract files into it.
@titusfortner
This error occurs only when trying to download a file larger than the shutil.COPY_BUFSIZE.
The cause is that the name of the zip-file is the same as the name of the destination file.
I could write a test, but that would require adding a larger file.
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
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.
User description
Fix #13957, #13956
Description
Motivation and Context
Types of changes
Checklist
PR Type
Bug fix
Description
EOFErrorin thedownload_filemethod ofRemote WebDriverby using a temporary directory to handle zip files.tempfileimport to manage temporary directories.Changes walkthrough 📝
webdriver.py
Fix EOFError in `download_file` method by using temporary directorypy/selenium/webdriver/remote/webdriver.py
tempfileimport.download_filemethod to use a temporary directory forhandling zip files.
correctly.