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

Ask a question with upload a file, then response: An error occured: UnicodeDecodeError: 'gbk' codec can't decode byte #2716

Open
loverubywithout opened this issue Feb 14, 2025 · 0 comments

Comments

@loverubywithout
Copy link

I upload a python file at web gui, and I ask a question.

the response is:

An error occured: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 1041: illegal multibyte sequence

the cmd error log:

Caused by:
    operation timed out
ERROR:g4f.gui.server.api:'gbk' codec can't decode byte 0xa4 in position 1041: illegal multibyte sequence
Traceback (most recent call last):
  File "e:\develop\github\ai\gpt4free\g4f\gui\server\api.py", line 167, in _create_response_stream
    for chunk in result:
  File "e:\develop\github\ai\gpt4free\g4f\tools\run_tools.py", line 190, in iter_run_tools
    new_message_content = re.sub(r'{"bucket_id":"([^"]*)"}', on_bucket, message["content"])
  File "E:\Anaconda\envs\ai\lib\re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "e:\develop\github\ai\gpt4free\g4f\tools\run_tools.py", line 186, in on_bucket
    return "".join(read_bucket(get_bucket_dir(match.group(1))))
  File "e:\develop\github\ai\gpt4free\g4f\tools\files.py", line 257, in read_bucket
    yield cache_file.read_text()
  File "E:\Anaconda\envs\ai\lib\pathlib.py", line 1135, in read_text

then I re-write the File "e:\develop\github\ai\gpt4free\g4f\tools\files.py", line 257, in read_bucket

cache_file.read_text() -> cache_file.read_text('utf-8')

def read_bucket(bucket_dir: Path):
    bucket_dir = Path(bucket_dir)
    cache_file = bucket_dir / PLAIN_CACHE
    spacy_file = bucket_dir / f"spacy_0001.cache"
    if not spacy_file.exists():
        # yield cache_file.read_text()
        yield cache_file.read_text('utf-8')

then I slove the problem.


ps: I tried adding #-*- coding: utf-8 -*- at the beginning of the py file, but it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant