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

Error: Expected a bytes-like object, str found #108

Open
dayzdayz opened this issue Oct 3, 2016 · 1 comment
Open

Error: Expected a bytes-like object, str found #108

dayzdayz opened this issue Oct 3, 2016 · 1 comment

Comments

@dayzdayz
Copy link

dayzdayz commented Oct 3, 2016

I'm new to GitHub and Python, although not programming. I've got as far as I can with this but now I need help.

I am running Python 3.5.2, Windows 10 and using IDLE.
I have placed encrypt.dll in the root directory where I run my main script and have passed in 'encrypt.dll' to the session. This error then gets thrown during util.hashSignature:

Traceback (most recent call last):
cells = self.session.getMapObjects(bothDirections=False)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\pogo\session.py", line 88, in getMapObjects
res = self.wrapAndRequest(payload)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\pogo\session_bare.py", line 288, in wrapAndRequest
res = self.request(self.wrapInRequest(payload, defaults=defaults))
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\pogo\session_bare.py", line 236, in wrapInRequest
signature = hashSignature(proto, self.encryptLib)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\pogo\util.py", line 151, in hashSignature
return b''.join(map(chr, output))
TypeError: sequence item 0: expected a bytes-like object, str found

I've searched and only found one other person who got the same problem: #85
but it's not clear how he resolved his problem, other than switching to Python 2.7.

Is this known to work with Python 3.5.2 or do I need to start over in 2.7?
Is it possible I didn't get the correct version of encrypt.dll and if so where can I find a fix?

@dayzdayz
Copy link
Author

dayzdayz commented Oct 5, 2016

So I did some digging and found a fix.

TLDR: To make it work in Python 3.5, in pogo\util.py add the following line to the imports:
import six
and change this line in hashSignature:
return b''.join(map(chr, output))
to:
return b''.join(list(map(lambda x: six.int2byte(x), output)))

Firstly, I didn't realise there are different versions of the encrypt.dll available for 32 bit and 64 bit. I tried both. If you have the wrong version it will give you an error message like: OSError: [WinError 193] %1 is not a valid Win32 application

So having established that I have the correct version of encrypt.dll, I discovered that Python 3.5 and Python 2.7 handle bytes and strings differently. Python 2.7 allows you to interchange the two while Python 3.5 is much stricter. Here is some more info on this:
https://www.python.org/dev/peps/pep-0404/#strings-and-bytes
https://docs.python.org/3/howto/pyporting.html#text-versus-binary-data

I found a fix in a similar app and implemented it locally (as described in the TLDR above) and it now works on Python 3.5.

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

1 participant