terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
724 stars 155 forks source link

UnicodeEncodeError #78

Closed sameertak closed 3 years ago

sameertak commented 3 years ago

Whenever I try to run this line of code:-

with open('output.txt', mode='r+') as my_file2: translator = Translator(to_lang="ja") translation = translator.translate(a) my_file2.write(translation)

It shows me:- UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to

sameertak commented 3 years ago

I need to change the line: - with open('output.txt', mode='r+') as my_file2: to with open('output.txt', "w", encoding="utf-8") as my_file2: