Fix UnicodeDecodeError: Ensure UTF-8 encoding when reading JSON config#353
Open
a-cidm wants to merge 1 commit intoNVIDIA:mainfrom
Open
Fix UnicodeDecodeError: Ensure UTF-8 encoding when reading JSON config#353a-cidm wants to merge 1 commit intoNVIDIA:mainfrom
a-cidm wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
This was referenced Mar 9, 2025
ice-fly
approved these changes
May 10, 2025
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.
Fix UnicodeDecodeError: Ensure UTF-8 encoding when reading JSON config
Problem
This error occurs when the script attempts to read LoRA configuration files (or other related JSON files) that contain special characters outside of the default encoding (CP1252 on Windows). If the file includes characters not supported by this encoding, Python throws the following error:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1011: character maps to <undefined>Cause
By default, Python’s
open()function reads files using the system's default encoding, which on Windows is oftencp1252. If the file is actually encoded in UTF-8 and contains special characters, this leads to a decoding failure.Solution
The fix enforces UTF-8 encoding when opening JSON config files, ensuring compatibility with special characters. This is done by modifying:
To:
This change ensures that the script correctly handles files with Unicode characters, preventing crashes due to encoding mismatches.
Closes #239