Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100462
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: subprocess.call with non-ASCII arguments? |
| Date | 2015-12-15 16:08 +0100 |
| Message-ID | <mailman.23.1450192114.22044.python-list@python.org> (permalink) |
| References | <n4p7te$jrg$1@news2.informatik.uni-stuttgart.de> |
In a message of Tue, 15 Dec 2015 14:25:50 +0000, Ulli Horlacher writes: >(My first posting seems to got lost) > >I want to create a zip file within a Python 2.7 program on windows. > >My code: > > cmd = ['7za.exe','a','-tzip',archive] + files > status = subprocess.call(cmd) > >leads to: > > File "fexit.py", line 971, in sendfile_retry > status = subprocess.call(cmd) > File "C:\Python27\lib\subprocess.py", line 522, in call > return Popen(*popenargs, **kwargs).wait() > File "C:\Python27\lib\subprocess.py", line 710, in __init__ > errread, errwrite) > File "C:\Python27\lib\subprocess.py", line 958, in _execute_child > startupinfo) >UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 87: > ordinal not in range(128) > > >This is because the array "files" contains filenames with non-ASCII >characters. > >So, the problem is in subprocess.py, which I cannot modify. > > >Instead of calling a 7z subprocess with non-ASCII arguments I tried to >call it with a listfile: it starts with a "@" and contains the names of >the files to be packed into the arcive. It is a special 7z feature. > >New code: > > fileslist = archive + '.list' > flo = open(fileslist,'w') > for file in files: print(file,file=flo) > flo.close() > cmd = ['7za.exe','a','-tzip',archive,'@'+fileslist] > status = subprocess.call(cmd) > > >But with that I get a new error: > > File "fexit.py", line 959, in sendfile_retry > for file in files: print(file,file=flo) >UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 8: > ordinal not in range(128) > > >I get the same error message, when i use: > flo = open(fileslist,'wb') > > >How can I tell open() or print() that I want to write non-ASCII ? see if setting the environment variable PYTHONIOENCODING https://docs.python.org/2/using/cmdline.html works for you. No promises, not a windows user. Laura
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
subprocess.call with non-ASCII arguments? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-15 14:25 +0000
Re: subprocess.call with non-ASCII arguments? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-15 10:03 -0500
Re: subprocess.call with non-ASCII arguments? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-15 17:57 +0000
Re: subprocess.call with non-ASCII arguments? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-15 21:20 -0500
Re: subprocess.call with non-ASCII arguments? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-16 12:44 +0000
Re: subprocess.call with non-ASCII arguments? wxjmfauth@gmail.com - 2015-12-16 06:55 -0800
Re: subprocess.call with non-ASCII arguments? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-15 15:05 +0000
Re: subprocess.call with non-ASCII arguments? Laura Creighton <lac@openend.se> - 2015-12-15 16:08 +0100
csiph-web