From f8f3063ce111c68022ca91c470daa6067ea4f1ed Mon Sep 17 00:00:00 2001 From: resteve Date: Thu, 12 Feb 2015 17:43:33 +0100 Subject: [PATCH] Process Popen force utf-8 --- translate.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/translate.py b/translate.py index e4f7001..df716e0 100644 --- a/translate.py +++ b/translate.py @@ -35,9 +35,14 @@ class TranslateWizardTranslation: @classmethod def get_translation_from_apertium(cls, text, source_lang, target_lang): - proccess = Popen('echo "%s" | apertium %s-%s' % - (text, source_lang[:2], target_lang[:2]), - shell=True, stdout=PIPE, stderr=PIPE) + cmd = 'echo "%s" | apertium %s-%s' % ( + text, + source_lang[:2], + target_lang[:2], + ) + # force utf8 - TypeError: execv() arg 2 must contain only strings + cmd = cmd.encode('utf-8') + proccess = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) out, error = proccess.communicate() if error: cls.raise_user_error('error_translating', error_args=(text,))