epub_convert icon indicating copy to clipboard operation
epub_convert copied to clipboard

Converter give error: cannot use a string pattern on a bytes-like object

Open simongcc opened this issue 2 years ago • 2 comments

There is an error like this

  File "/somewhere/miniforge3/lib/python3.10/site-packages/opencc/opencc.py", line 67, in convert
    split_string_list = self.split_chars_re.split(string)
TypeError: cannot use a string pattern on a bytes-like object

So the solution is adding a checking to the string returned by the converter like this

def s2t(text):
    if isinstance(text, bytes):
        text = text.decode('utf-8')  # decode bytes to string using utf-8 encoding
    return converter.convert(text)

Then the error will be resolved. Tested with Simplified Chinese to Traditional Chinese

simongcc avatar Sep 09 '23 07:09 simongcc

@simongcc Hi, can I have an example file which make this error occur? thanks

t510599 avatar Sep 21 '23 02:09 t510599

@t510599 Hi Tony, sorry for late reply for I was travelling for a few months. I have forgotten which book I have used for testing about it. If I happen to see again will let you know.

jingcodeguy avatar Jun 18 '24 04:06 jingcodeguy