pokemongo-api icon indicating copy to clipboard operation
pokemongo-api copied to clipboard

Error: Expected a bytes-like object, str found

Open dayzdayz opened this issue 9 years ago • 1 comments

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: https://github.com/rubenvereecken/pokemongo-api/issues/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 avatar Oct 03 '16 22:10 dayzdayz

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.

dayzdayz avatar Oct 05 '16 11:10 dayzdayz