fix issue #297: UnicodeEncodeError in date formatting for non-Chinese locale systems (issu#299
Open
jovicdev97 wants to merge 1 commit intozai-org:mainfrom
Open
fix issue #297: UnicodeEncodeError in date formatting for non-Chinese locale systems (issu#299jovicdev97 wants to merge 1 commit intozai-org:mainfrom
jovicdev97 wants to merge 1 commit intozai-org:mainfrom
Conversation
Author
|
修复 issue #297 问题: 错误信息: 修复方案: 修改内容: 修改前: |
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.
fixes issue #297
Problem:
Running the application on systems with non-Chinese locales causes a UnicodeEncodeError during import. The application crashes immediately on startup before any functionality can be used. The strftime() function uses the system's locale encoding to process the format string. On systems without Chinese locale support (e.g., cp1252 on German Windows), the characters 年, 月, 日 cannot be encoded.
Error Message:
File "...\phone_agent\config\prompts_zh.py", line 8, in <module> formatted_date = today.strftime("%Y年%m月%d日") + " " + weekday ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: encoding errorFix:
Replaced strftime() with f-string formatting to avoid locale-dependent encoding
Changes:
old:
formatted_date = today.strftime("%Y年%m月%d日") + " " + weekday.
.
.
new:
formatted_date = f"{today.year}年{today.month:02d}月{today.day:02d}日 {weekday}"