Python UnicodeEncodeError: codec cannot encode character

I created an executable from my python script (checkData.py)

I am trying to pass string data that includes locale characters to this exe file from another python script something like below:

...
dataPath = easygui.fileopenbox(msg, title)
p= subprocess.Popen(["checkData.exe",  dataPath], stdout = subprocess.PIPE )

      

When I type dataPath

from the calling script, I can see the locale characters. When I tried to print the line passed to the exe file, I got an error.

...
parser = ArgumentParser()
parser.add_argument("directory", action="store")
args = parser.parse_args()

print(args.directory)

      

Here is my error message:

C:\script\build\exe.win32-3.2>checkSi‌​mTestData.exe
  dataDirectoryPath= C:\samples\şample_test_data 
Traceback (most recent call last):
  File "c:\python32\lib\site-packages\cx_Freeze\initscripts\Console3.py",
    line 27, in <module> exec(code, m.__dict__)
  File "checkData.py",
    line 56, in <module>
  File "C:\Python\32-bit\3.2\lib\encodings\cp1254.py",
    line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\xfe'
  in position 80: character maps to <undefined> – 

      

When I run below command:

sys.stdout.encoding

      

I got "cp1254"

could you help me?

+3


source to share





All Articles