From 6a9407d7cc4ac5555180a2ee331ff95eef131902 Mon Sep 17 00:00:00 2001 From: strohu Date: Tue, 12 Jul 2016 15:47:01 +0100 Subject: [PATCH] Make sudo pfctl error check Python 3 compatible In Python 3, subprocess.check_output() returns a sequence of bytes. This change ensures that it will be converted to a string, so the substring test for the sudo error message does not raise a TypeError. This fixes the code in Python 3 while remaining compatible with Python 2. --- mitmproxy/platform/osx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitmproxy/platform/osx.py b/mitmproxy/platform/osx.py index b5dce7936..6a555f32e 100644 --- a/mitmproxy/platform/osx.py +++ b/mitmproxy/platform/osx.py @@ -23,12 +23,12 @@ class Resolver(object): try: stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - if "sudo: a password is required" in e.output: + if "sudo: a password is required" in e.output.decode(errors="replace"): insufficient_priv = True else: raise RuntimeError("Error getting pfctl state: " + repr(e)) else: - insufficient_priv = "sudo: a password is required" in stxt + insufficient_priv = "sudo: a password is required" in stxt.decode(errors="replace") if insufficient_priv: raise RuntimeError(