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

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

Open
JacobPimental opened this issue Jun 28, 2018 · 2 comments
Open

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

JacobPimental opened this issue Jun 28, 2018 · 2 comments

Comments

@JacobPimental
Copy link

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'

@mytbk
Copy link
Contributor

mytbk commented Aug 15, 2018

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.

@mytbk
Copy link
Contributor

mytbk commented Aug 15, 2018

This is the fix for 2.4.0 (looks like it's the current r2pipe-0.9.9)
mytbk@15ceaa5

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

No branches or pull requests

2 participants