Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix utf8 encoding error when opening resource_exceptions.json #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rstijerina
Copy link
Member

@rstijerina rstijerina commented Oct 11, 2019

Description

Instantiating an Agave object throws an exception in python 3.6, point of failure being the opening of the resource_exceptions.json file:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 8993: ordinal not in range(128)

Exception Traceback:

$ ipython
Python 3.6.8 (default, Aug  7 2019, 17:28:10)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from agavepy.agave import Agave

In [2]: Agave()
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-2-0cfaa5d4a0cc> in <module>
----> 1 Agave()

/usr/local/lib/python3.6/site-packages/agavepy/agave.py in __init__(self, **kwargs)
    269         if self.resources is None:
    270             self.resources = load_resource(self.api_server)
--> 271         self.resource_exceptions = json.load(open(os.path.join(HERE, 'resource_exceptions.json'), 'r'))
    272         self.host = urllib.parse.urlsplit(self.api_server).netloc
    273         if self.token_callback and not hasattr(self.token_callback, '__call__'):

/usr/lib64/python3.6/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    294
    295     """
--> 296     return loads(fp.read(),
    297         cls=cls, object_hook=object_hook,
    298         parse_float=parse_float, parse_int=parse_int,

/usr/lib64/python3.6/encodings/ascii.py in decode(self, input, final)
     24 class IncrementalDecoder(codecs.IncrementalDecoder):
     25     def decode(self, input, final=False):
---> 26         return codecs.ascii_decode(input, self.errors)[0]
     27
     28 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 8993: ordinal not in range(128)

This can be fixed by opening the file with an encoder='utf-8' specified.

Motivation and Context

Necessary in order to instantiate Agave objects via from agavepy.agave import Agave.

  • I have raised an issue to propose this change (required)

How Has This Been Tested?

Tested with IPython 7.8.0 and Python 3.6.8 in a CentOS 7 docker container.

$ pip install git+https://github.com/rstijerina/agavepy
$ ipython
Python 3.6.8 (default, Aug  7 2019, 17:28:10)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from agavepy.agave import Agave

In [2]: Agave()
Out[2]: <agavepy.agave.Agave at 0x7faef42e51d0>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant