ConstError: expected b'\x00\x0b' but parsed b'\x00\x00' -> expected 3 to 3, found 0
Namek opened this issue · 4 comments
Namek commented
Traceback (most recent call last):
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 2784, in _parse
return self.subcon._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 295, in _parse
return self.subcon._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 1594, in _parse
obj = self.cases.get(key, self.default)._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 1936, in _parse
raise ConstError("expected %r but parsed %r" % (self.value, obj))
construct.core.ConstError: expected b'\x00\x0b' but parsed b'\x00\x00'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 1042, in _parse
obj.append(self.subcon._parse(stream, context._, path))
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 2788, in _parse
raise e.__class__("%s\n %s" % (e, path))
construct.core.ConstError: expected b'\x00\x0b' but parsed b'\x00\x00'
(parsing) -> initial -> players
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 2784, in _parse
return self.subcon._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 1050, in _parse
raise RangeError("expected %d to %d, found %d" % (min, max, len(obj)))
construct.core.RangeError: expected 3 to 3, found 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\ant_league\backend\lib\site-packages\mgz\summary\__init__.py", line 73, in __init__
self._header = mgz.header.parse_stream(self._handle)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 171, in parse_stream
return self._parse(stream, context2, "(parsing)")
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 295, in _parse
return self.subcon._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 295, in _parse
return self.subcon._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\mgz\util.py", line 57, in _parse
return self.subcon._parse(new_stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 357, in _parse
return self.subcon.parse(data, context)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 158, in parse
return self.parse_stream(BytesIO(data), context, **kw)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 171, in parse_stream
return self._parse(stream, context2, "(parsing)")
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "C:\dev\ant_league\backend\lib\site-packages\construct\core.py", line 2788, in _parse
raise e.__class__("%s\n %s" % (e, path))
construct.core.RangeError: expected 3 to 3, found 0
(parsing) -> initial
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\ant_league\backend\lib\site-packages\bottle.py", line 868, in _handle
return route.call(**args)
File "C:\dev\ant_league\backend\lib\site-packages\bottle.py", line 1748, in wrapper
rv = callback(*a, **ka)
File "C:\dev\ant_league\backend\lib\site-packages\bottle_sqlite.py", line 141, in wrapper
rv = callback(*args, **kwargs)
File "C:\dev\ant_league\backend\website.py", line 164, in post_match
match_info = get_match_info(file.file)
File "C:\dev\ant_league\backend\website.py", line 48, in get_match_info
s = Summary(data)
File "C:\dev\ant_league\backend\lib\site-packages\mgz\summary\__init__.py", line 85, in __init__
raise RuntimeError("invalid mgz file: {}".format(e))
RuntimeError: invalid mgz file: expected 3 to 3, found 0
(parsing) -> initial
gethvi commented
I also encountered this error while trying to get the Summary of a game. I managed to track the problem down to this line:
Line 64 in f59d3a4
Changing it to Const(b'\x00\x00')
didn't help. I replaced it with Bytes(2)
and it worked.
triplejberger commented
I get a similar issue when trying to run the example code from the ReadMe
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 2784, in _parse
return self.subcon._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 1936, in _parse
raise ConstError("expected %r but parsed %r" % (self.value, obj))
construct.core.ConstError: expected b'`\n' but parsed b'\x00`'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 29, in <module>
header.parse_stream(data)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 171, in parse_stream
return self._parse(stream, context2, "(parsing)")
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 295, in _parse
return self.subcon._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 295, in _parse
return self.subcon._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/mgz/util.py", line 57, in _parse
return self.subcon._parse(new_stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 357, in _parse
return self.subcon.parse(data, context)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 158, in parse
return self.parse_stream(BytesIO(data), context, **kw)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 171, in parse_stream
return self._parse(stream, context2, "(parsing)")
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 867, in _parse
subobj = sc._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 2784, in _parse
return self.subcon._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 1594, in _parse
obj = self.cases.get(key, self.default)._parse(stream, context, path)
File "/Users/user/Library/Python/3.8/lib/python/site-packages/construct/core.py", line 2788, in _parse
raise e.__class__("%s\n %s" % (e, path))
construct.core.ConstError: expected b'`\n' but parsed b'\x00`'
(parsing) -> de -> de
happyleavesaoc commented
@Namek I looked at that rec, not yet sure what the problem is. In the meantime, you can use the fast
parser, which seems to work fine on that rec.
@triplejberger can you provide your rec please?
happyleavesaoc commented
Closing since this issue manifested on older recs. Please open a new issue if anyone has a specific usecase and needs a fix.