Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated for python 3 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

updated for python 3 #1

wants to merge 1 commit into from

Conversation

jonathanng
Copy link

No description provided.

@jamestaylr
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants