I have a django site where I need to call a script using subprocess. The subprocess call works when I'm using ascii characters but when I try to issue arguments that are utf-8 encoded, I get an error:
execv() arg 2 must contain only strings.
The string u'Wiadomo\u015b\u0107'
is coming from a postgres db. This example is using polish words. When I run it using english words, I have no issues.
The call looks like this:
subprocess.Popen(['/usr/lib/p3web2/src/post_n_campaigns.py', '-c', u'bm01', '-1', u'Twoja', '-2', u'Wiadomo\u015b\u0107', '-3', u'', '-4', u'', '-5', u'', '-6', u'', '-m', u'pl', '-p', 'yes'])
I'm not sure how to handle the strings in this case. The odd thing is that this works fine when i run it through the python interpreter.
You should encode the Unicode strings in the encoding your program expects. If you know the program expects UTF-8:
u'Wiadomo\u015b\u0107'.encode('utf8')
If you don't know what encoding you need, you could try your platform's default encoding:
u'Wiadomo\u015b\u0107'.encode()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With