TypeError: a bytes-like object is required, not 'str'
JacobPimental opened this issue · 2 comments
I'm trying to use r2pipe in Python 3 and keep running into the error "TypeError: a bytes-like object is required, not 'str'" when using the cmd() function. I have updated r2pipe via pip3, updated r2 to the latest version, and even updated r2pm just in case that would help any. I am running this on a Manjaro Linux machine, though I'm not sure if that would cause any problems. Here is the exact error I am getting:
Traceback (most recent call last):
File "test.py", line 4, in
r2.cmd( 'aa' )
File "/usr/lib/python3.6/site-packages/r2pipe/init.py", line 274, in cmd
res = self._cmd(cmd)
File "/usr/lib/python3.6/site-packages/r2pipe/init.py", line 214, in _cmd_pipe
os.write(self.pipe[1], cmd)
TypeError: a bytes-like object is required, not 'str'
There are some places to change, e.g.:
def _cmd_pipe(self, cmd):
- out = ''
+ out = b''
cmd = cmd.strip().replace("\n", ";")
if os.name == "nt":
windll.kernel32.WriteFile(self.pipe[1], cmd, len(cmd), byref(cbWritten), None)
@@ -137,7 +137,7 @@ class OpenBase(object):
out = out[0:-1]
break
else:
- os.write(self.pipe[1], cmd)
+ os.write(self.pipe[1], cmd.encode())
while True:
res = os.read(self.pipe[0], 4096)
if res[-1] == b'\x00':
It looks like the r2pipe in pypi is the 2.4.0 release of this repo, but the current HEAD version changed a lot. I think you can modify the py files in your installed files.
This is the fix for 2.4.0 (looks like it's the current r2pipe-0.9.9)
mytbk@15ceaa5