"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "2680078c137a93e12a55392a7e4d64632c58fb7b"
Unverified Commit faad1664 authored by Xiaomeng Zhao's avatar Xiaomeng Zhao Committed by GitHub
Browse files

Merge pull request #1231 from icecraft/fix/unicode_write

fix: unicode decode error
parents c5a4150e 11344890
...@@ -48,4 +48,16 @@ class DataWriter(ABC): ...@@ -48,4 +48,16 @@ class DataWriter(ABC):
path (str): the target file where to write path (str): the target file where to write
data (str): the data want to write data (str): the data want to write
""" """
self.write(path, data.encode())
def safe_encode(data: str, method: str):
try:
bit_data = data.encode(encoding=method, errors='replace')
return bit_data, True
except: # noqa
return None, False
for method in ['utf-8', 'ascii']:
bit_data, flag = safe_encode(data, method)
if flag:
self.write(path, bit_data)
break
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment