pytorctl icon indicating copy to clipboard operation
pytorctl copied to clipboard

updated for python 3

Open jonathanng opened this issue 9 years ago • 1 comments

jonathanng avatar Nov 27 '16 13:11 jonathanng

Thanks for starting this! I had to also change arguments to write and recv, which expect / return bytes in Python3.

diff --git a/TorCtl/TorCtl.py b/TorCtl/TorCtl.py
index 692b10e..16082a7 100755
--- a/TorCtl/TorCtl.py
+++ b/TorCtl/TorCtl.py
@@ -867,7 +867,7 @@ class Connection:
       if len(lines) > 2:
         amsg = "\n".join(lines[:2]) + "\n"
       self._debugFile.write(str(time.time())+"\t>>> "+amsg)
-    self._s.write(msg)
+    self._s.write(msg.encode())

   def set_timer(self, in_seconds, type=None):
     event = (("650", "TORCTL_TIMER", type),)
diff --git a/TorCtl/TorUtil.py b/TorCtl/TorUtil.py
index 3c7a9c5..5d39451 100644
--- a/TorCtl/TorUtil.py
+++ b/TorCtl/TorUtil.py
@@ -200,7 +200,7 @@ class BufSock:
         return result

     while 1:
-      s = self._s.recv(128)
+      s = self._s.recv(128).decode('utf-8')
       if not s: return None
       # XXX: This really does need an exception
       #  raise ConnectionClosed()

Without this change, a TypeError is raised:

TypeError: a bytes-like object is required, not 'str'

jamestaylr avatar May 15 '18 01:05 jamestaylr