tejado / pgoapi

Pokemon Go API lib
Other
1.4k stars 445 forks source link

No more JSON output ? #60

Closed drallieiv closed 8 years ago

drallieiv commented 8 years ago

I tried a previous version earlier today (on another desktop) and the output was in nice JSON with format(json.dumps(response_dict, indent=2)))

I tried changing changing back from pprint.PrettyPrinter to json.dumps but It no longer works. but now I get errors : TypeError: b'/yVMMtOIff1pLzN/MxHIDBcVjLdCIm6n01fIwhSiEqoinLB+jc6fY5c2MSud5ysV7hBfrZqUbgATBOgE3K8zBA==' is not JSON serializable

Any idea why ?

tejado commented 8 years ago

The output was never JSON but a dict. As the dict now contains some binary data, it is uncompatible with JSON as this is not a native type of it. Please use pprint like in my pokecli.py :)

drallieiv commented 8 years ago

The thing is that I was parsing the output in Javascript (with a JSON.parse()) to display it nicely in html.

I tried using the pprint format, but I haven't found any library than can reads it, and do not plan on making my own.

tejado commented 8 years ago

A recursive function which will decode all bytes of the dict could be a solution. Then JSON.dump can be used again.

tejado commented 8 years ago

@drallieiv Did you found a solution?

drallieiv commented 8 years ago

@tejado I'm still using an older version of the project with the previous protofiles.

tejado commented 8 years ago

I added an JSONByteEncoder https://github.com/tejado/pgoapi/commit/ebffcdb60815a338d8a4171f8a33577e8dccb66f which should resolve your issue.

Example: https://github.com/tejado/pgoapi/blob/master/pokecli.py#L163