Skip to content

Error on opening co-op replays in 1.6.0 #126

@jcfieldsdev

Description

@jcfieldsdev

Using the latest version of sc2reader available on PIP, sc2reader chokes when opening co-op replays that use factions besides the standard multiplayer ones. I did not encounter this error previously on version 1.5.0.

Here is a sample replay.

Here is a simple test script that uses that replay to demonstrate the issue:

#!/usr/bin/env python3

import sc2reader

replay = sc2reader.load_replay('./Miner Evacuation (64).SC2Replay', load_level=2)

It gives me the following error when executed:

Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    replay = sc2reader.load_replay('./Miner Evacuation (64).SC2Replay', load_level=2)
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/factories/sc2factory.py", line 85, in load_replay
    return self.load(Replay, source, options, **new_options)
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/factories/sc2factory.py", line 143, in load
    return self._load(cls, resource, filename=filename, options=options)
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/factories/sc2factory.py", line 152, in _load
    obj = cls(resource, filename=filename, factory=self, **options)
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/resources.py", line 301, in __init__
    self._read_data(data_file, self._get_reader(data_file))
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/resources.py", line 902, in _read_data
    self.raw_data[data_file] = reader(data, self)
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/readers.py", line 303, in __call__
    result = [
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/readers.py", line 304, in <listcomp>
    Attribute(
  File "/Users/jcfields/Library/Python/3.8/lib/python/site-packages/sc2reader/objects.py", line 80, in __init__
    self.value = lookup[value.strip("\x00 ")[::-1]]
KeyError: 'InfT'

The problem seems to be that the "InfT" (Infested Terran) race used on the Miner Evacuation mission is not in the "attributes.json" file (which only has the standard Terran, Zerg, Protoss, and Random), so its presence in the replay file causes a key look-up error.

I looped through all of my co-op replays and found the following non-standard races that cause read errors:

  • InfT
  • ProZ
  • PZrg
  • TerH
  • TerT

I don't know if this is an exhaustive list, but it's a pool of over 1,000 co-op replays.

I would guess that either adding these races to "attributes.json" or implementing some sort of fallback to prevent a fatal error if a non-standard race can't be identified would fix this issue.

Edit: Using sc2reader 1.6.0, Python 3.8.5, Mac OS 10.14.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions