Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100462

Re: subprocess.call with non-ASCII arguments?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Laura Creighton <lac@openend.se>
Newsgroups comp.lang.python
Subject Re: subprocess.call with non-ASCII arguments?
Date Tue, 15 Dec 2015 16:08:23 +0100
Lines 67
Message-ID <mailman.23.1450192114.22044.python-list@python.org> (permalink)
References <n4p7te$jrg$1@news2.informatik.uni-stuttgart.de>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de ipqMR7TzQHEf8KV9R2PLNAQNBXlRRUziHsYf2bVrMTJw==
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'subject:skip:s 10': 0.05; 'feature.': 0.07; 'filenames': 0.07; 'cc:addr:python-list': 0.09; '__init__': 0.09; 'cmd': 0.09; 'encode': 0.09; 'errread,': 0.09; 'files:': 0.09; 'non-ascii': 0.09; 'open()': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'skip:[ 30': 0.09; 'skip:[ 40': 0.09; 'python': 0.10; '2.7': 0.13; 'user.': 0.15; '"@"': 0.16; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'codec': 0.16; 'errwrite)': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'ordinal': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:> 20': 0.16; 'subject:non': 0.16; 'subprocess': 0.16; 'laura': 0.18; 'archive': 0.18; 'variable': 0.18; 'windows': 0.20; '2015': 0.20; 'cc:addr:python.org': 0.20; 'skip:" 30': 0.20; 'cc:2**1': 0.22; 'arguments': 0.22; 'seems': 0.23; 'dec': 0.23; 'tried': 0.24; 'error': 0.27; 'received:se': 0.29; 'environment': 0.29; 'array': 0.29; 'cc:no real name:2**1': 0.29; 'character': 0.29; 'code:': 0.29; 'starts': 0.29; "can't": 0.32; 'skip:_ 10': 0.32; 'posting': 0.32; 'problem': 0.33; 'url:python': 0.33; 'windows.': 0.33; 'tue,': 0.34; 'file': 0.34; 'url:org': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'setting': 0.37; 'charset:us-ascii': 0.37; 'names': 0.38; 'skip:p 20': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'subject:-': 0.39; 'subject:with': 0.40; 'header:Message- Id:1': 0.61; 'within': 0.64; 'you.': 0.64; 'special': 0.73; '>how': 0.84; 'header:In-reply-to:1': 0.84; 'modify.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=openend.se; s=default; t=1450192104; bh=R87M9OHgrWq0EHbhZb1t1mE5BdkTYdhpX2L3lvPJfyo=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=DnZE/f/L21BzgUS9KnaLCPjyAVDwqTL6V+V0wu25lt2EQgcKx466lrp9SN0FLbUgI dE/DGkVXvxZYU3G//f2PGr+oOr1ebTgelUPZ0WxUrBXlkiJjja0remGRlfj69Z8+JY GFkTzI3ceeC7g4cssGNsFuTrj9ncKZtpWs72ManI=
In-reply-to <n4p7te$jrg$1@news2.informatik.uni-stuttgart.de>
Comments In-reply-to Ulli Horlacher <framstag@rus.uni-stuttgart.de> message dated "Tue, 15 Dec 2015 14:25:50 +0000."
Content-ID <32719.1450192103.1@fido>
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Tue, 15 Dec 2015 16:08:24 +0100 (CET)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100462

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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