ericmburgess / python-factorio

Factorio is a game about automation. Let's automate it.
MIT License
58 stars 9 forks source link

Unable to decode blueprint strings #7

Open jab416171 opened 7 years ago

jab416171 commented 7 years ago

It looks like the code should be able to take in a blueprint string generated from Factorio and output JSON, however when I try to do that I get a stack trace:

Traceback (most recent call last):
  File "scripts/to_exchange.py", line 19, in <module>
    blob = EncodedBlob.from_exchange_file(input)
  File "/home/me/src/factorio-blueprint-compendium/scripts/python_factorio/blueprints.py", line 43, in from_exchange_file
    return cls.from_exchange_string(open(filename).read().strip())
  File "/home/me/src/factorio-blueprint-compendium/scripts/python_factorio/blueprints.py", line 38, in from_exchange_string
    data = json.loads(json_str, object_pairs_hook=collections.OrderedDict)
  File "/usr/lib64/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

I fixed this by adding .decode('ascii') to line 37 (which I can gladly submit as a pull request), however even with this change, the library chokes when I give it a blueprint book.

EmperorArthur commented 6 years ago

I've fixed it in Pull #9. The problem is the code was written for Python2, and you're attempting to run it with Python3. The pull request makes the code Python3 compatible.