From b25e80188aabacb88f4c1bdc4b7c9c549c5982d9 Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Tue, 24 Apr 2018 15:02:17 +0900 Subject: [PATCH] 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. --- moto/core/responses.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moto/core/responses.py b/moto/core/responses.py index ed4792083..0f133e72c 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -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']