From 648965c97c82d1aee45de696bba5eec19aa722e4 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Fri, 21 Jul 2017 13:13:17 +0100 Subject: Python 3/2 compatibility: Convert Byte-str to Str Encoded Unicode in Python 3 is represented as binary data. The difference with Python2 is that any attempt to mix text and data in Python 3.0 raises TypeError, whereas if you were to mix Unicode and 8-bit strings in Python 2.x, it would work if the 8-bit string happened to contain only 7-bit (ASCII) bytes, but you would get UnicodeDecodeError if it contained non-ASCII values. Reference: https://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit Example: Python 2: >>> b'foo.bar'.split('.') ['foo', 'bar'] Python 3: >>> b'foo.bar'.split('.') Traceback (most recent call last): File "", line 1, in TypeError: a bytes-like object is required, not 'str' >>> b'foo.bar'.split(b'.') [b'foo', b'bar'] --- src/virtBootstrap/virt_bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/virtBootstrap/virt_bootstrap.py') diff --git a/src/virtBootstrap/virt_bootstrap.py b/src/virtBootstrap/virt_bootstrap.py index 85aca33..c66cc92 100755 --- a/src/virtBootstrap/virt_bootstrap.py +++ b/src/virtBootstrap/virt_bootstrap.py @@ -77,7 +77,7 @@ def set_root_password(rootfs, password): users = 'root:%s' % password args = ['chpasswd', '-R', rootfs] chpasswd = Popen(args, stdin=PIPE) - chpasswd.communicate(input=users) + chpasswd.communicate(input=users.encode('utf-8')) if chpasswd.returncode != 0: raise CalledProcessError(chpasswd.returncode, cmd=args, output=None) -- cgit