AWSServiceSpec: Fix TypeError exceptions within json.load()

The load() method provided by the built-in JSON module does not accept a
byte-type value in Python 3.5 (or versions before), and will raise an
exception if one is passed.

For details, please see: https://bugs.python.org/issue17909

Thus, for better compatibility, we'd better decode the content of the
JSON file before passing it to the parser, instead of letting the module
to guess the encoding.
This commit is contained in:
Fujimoto Seiji 2018-04-24 15:02:17 +09:00
parent 21a264c337
commit b25e80188a

View File

@ -5,6 +5,7 @@ import datetime
import json
import logging
import re
import io
import pytz
from moto.core.exceptions import DryRunClientError
@ -622,7 +623,7 @@ class AWSServiceSpec(object):
def __init__(self, path):
self.path = resource_filename('botocore', path)
with open(self.path, "rb") as f:
with io.open(self.path, 'r', encoding='utf-8') as f:
spec = json.load(f)
self.metadata = spec['metadata']
self.operations = spec['operations']