heroprotocol
heroprotocol copied to clipboard
TypeError in `python -m heroprotocol --initdata --json ...`
Hi @Agilhardt,
I have a tool to analyze my SL win rates. I used to use heroprotocol
as a submodule. After some time of not touching the tool, I pulled the latest heroprotocol
version to parse new replays and I've noticed that there were some breaking changes and my script no longer works. I started porting my tool to Python 3 and switched to using heroprotocol
installed via PyPI. However when I'm trying to run it, I'm getting an error from heroprotocol
. My tool runs --initdata --json
and it gets:
> python -m heroprotocol --initdata --json '/Users/narf/github/hots-winrate/replays/2019-06-19 22.28.46 Garden of Terror.StormReplay'
Traceback (most recent call last):
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/narf/.pyenv/versions/hots-winrate/lib/python3.8/site-packages/heroprotocol/__main__.py", line 10, in <module>
hero_cli.main()
File "/Users/narf/.pyenv/versions/hots-winrate/lib/python3.8/site-packages/heroprotocol/hero_cli.py", line 96, in main
logger.log(
File "/Users/narf/.pyenv/versions/hots-winrate/lib/python3.8/site-packages/heroprotocol/hero_cli.py", line 33, in log
print(json_dumps(event, encoding='iso-8859-1'))
File "/Users/narf/.pyenv/versions/hots-winrate/lib/python3.8/site-packages/heroprotocol/compat.py", line 13, in json_dumps
return json.dumps(obj, ensure_ascii=True)
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/Users/narf/.pyenv/versions/3.8.2/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
When I run it without --json
there's indeed some binary before the dictionary that I expected to read as JSON:
[b's2ma\x00\x00EU\x1f\x1b"\x8d\xdb\x1fr \\\xbf\xd4D\x05R\x87\x10\x0b\x0f9\x95\x9b\xe8\x16T\x81b\xe4\x08\x1e\xa8U\x11',
b's2ma\x00\x00EU\x1a\xd9L\x12n\xb9\x8aL\x1d\xe7\xb8\xe6\xf8\xaa\xa1S\xdb\xa5+\t\xd3\x82^\x0c\x89\xdb\xc5\x82'
b'\x8d\xb7\x0fv',
b's2ma\x00\x00EU\x92\xd8\x17D\xc1D\x1b\xf6(\xedj\xb7\xe9\xd1\x94\x85\xc8`\x91M\x8btZ\x91\xf65\x1f\xf9\xdc\xd4\xe6\xbb',
b's2ma\x00\x00EU\xa1\xe9\xab\xcd?\xd2PS\xc9\x03\xab\x13R\xa6\x85u7(K2\x9d\x08\xb8k+\xe2\xdeI\xc3\xab\x7fC',
b's2ma\x00\x00EU\xfex\xac\xfb\xed8\xbb\x00\x1d\xbd\xa0\xc1\x9c\xc0\x17\xf9\x02m\xb7]\xf7}\x95s\xe1\xb1*\xc3'
b'\xca\xb3\r\x92',
b's2ma\x00\x00EU%Cz9\x8d\x95\x8a\xa7\xdb|E\x104\x99\xbd\x89\xa1\xfa\x8c\xf1E\x08\xeb\xd1\xb1\xcc\x08\xdbI}\xc9\x8d']
{'m_syncLobbyState': {'m_gameDescription': {'m_cacheHandles': [b's2ma\x00\x00EU\x1f\x1b"\x8d\xdb\x1fr \\\xbf\xd4D'
b'\x05R\x87\x10\x0b\x0f9\x95\x9b\xe8\x16T\x81b\xe4\x08'
b'\x1e\xa8U\x11',
Here are the versions that I'm using:
> python --version
Python 3.8.2
> pip freeze | ag hero
heroprotocol==2.50.2.80046
I believe this is a bug. Or should I run the new heroprotocol
in a different way? The only thing I'm using it for is filtering Storm League games and reading information about players: their name, hero name, team, party, and whether they won.
Thanks in advance for your help.
Thanks for the report, I'll check it out as soon as I can. I recall seeing this crop up during testing but thought I had nailed it.
I don't think it'll matter but for the sake of completeness, it looks like you're running on Mac?
Also, while you're working on your port, you can continue to use the legacy branch with your existing code. It isn't updated automatically like master
but I will try to make sure it doesn't lag too far behind.
Yes, I'm using a Mac. Thanks for info about the legacy
branch, it works with my old script.
Also seeing this same issue on wsl2.