Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly Handle Text File Encoding to Avoid 'GBK' Codec Errors #2072

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

jackiemoo
Copy link
Contributor

Problem:

The original read_text_file method encountered an error when importing a text file containing Chinese characters, specifically:

Error building vertex File: Error loading file /tmp/test.txt: 'gbk' codec can't decode byte 0xaf in position 7: illegal multibyte sequence

This error occurred due to incorrect or incompatible character encoding when reading the file.

Solution:

To resolve this issue, the method was updated to automatically detect the file's encoding using the chardet library. The new implementation reads the file in binary mode to determine the encoding and then reopens the file with the detected encoding to properly read its content.

Testing:

  • The updated method was tested with various text files containing Chinese characters and other encodings to ensure compatibility and proper functionality.

  • Files previously causing decoding errors were successfully read without issues after the update.

This PR resolves the encoding problem by implementing automatic encoding detection, improving the robustness and reliability of the read_text_file method when handling files with different character sets.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 5, 2024
Copy link

vercel bot commented Jun 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langflow ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2024 10:23am

@dosubot dosubot bot added the bug Something isn't working label Jun 5, 2024
Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jackiemoo

Good catch. Thank you!

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 5, 2024
@ogabrielluiz ogabrielluiz merged commit d8643d1 into langflow-ai:dev Jun 5, 2024
8 of 11 checks passed
@jackiemoo jackiemoo deleted the textencode branch June 5, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants