From 942d629d6e1a1548c70f71e855bc782da30f0f50 Mon Sep 17 00:00:00 2001 From: j3s Date: Sat, 16 May 2020 16:45:21 -0500 Subject: [PATCH] Decode bytes to string before comparing with regex - Python3 makes this a lil more complicated - see https://stackoverflow.com/questions/21689365/python-3-typeerror-must-be-str-not-bytes-with-sys-stdout-write --- capsulflask/virt_model.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/capsulflask/virt_model.py b/capsulflask/virt_model.py index 06099b9..39d472f 100644 --- a/capsulflask/virt_model.py +++ b/capsulflask/virt_model.py @@ -96,11 +96,12 @@ class ShellScriptVirtualization(VirtualizationInterface): completedProcess = run([join(current_app.root_path, 'shell_scripts/get.sh'), id], capture_output=True) self.validate_completed_process(completedProcess) lines = completedProcess.stdout.splitlines() + ipaddr = lines[0].decode("utf-8") - if not re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", lines[0]): + if not re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", ipaddr): return None - return VirtualMachine(id, ipv4=lines[0]) + return VirtualMachine(id, ipv4=ipaddr) def list_ids(self) -> list: completedProcess = run([join(current_app.root_path, 'shell_scripts/list-ids.sh')], capture_output=True)