Skip to content

urllib.urlload() and json.load() break when importing a SN model in Python 3 for the first time #83

Closed
@bcfriesen

Description

@bcfriesen

I tried importing the built-in supernova model 'hsiao' following the instructions on the SNCosmo website under the "Supernova Models" section. In Python 3, the line

model = sncosmo.Model(source='hsiao')

breaks with the error TypeError: can't use a string pattern on a bytes-like object. The error comes from this line in builtins.py:

urls = json.load(f)

which fails because the previous line,

f = urlopen("http://sncosmo.github.io/data/urls.json")

returns raw bytes in Python 3, whereas in Python 2 it returns a string (which is what json.load() expects).

This error does not occur in either version of Python if the requested SN model has already been downloaded and cached.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      urllib.urlload() and json.load() break when importing a SN model in Python 3 for the first time · Issue #83 · sncosmo/sncosmo