Skip to content

Instantly share code, notes, and snippets.

@suganoo suganoo/error_output.txt
Last active Jul 23, 2018

Embed
What would you like to do?
json パースでTypeError: string indices must be integers
self.filepath = self._get_value_from_messageattributes("filepath")
File "/xxxxxx/test.py", line 93, in _get_value_from_messageattributes
self.logger.debug("return value : %s", self.message["Message"][key]["Value"])
TypeError: string indices must be integers
{
"Subject" : "testtesttest",
"Message" : {
"filepath" : {"Value":"/xxxxxx/hogehogehoge.txt"}
}
}
import json
def _get_value_from_messageattributes(self, key):
# 一回読み込んで....
self.message = json.loads(message)
"""
"Message"以下が単なるStringになってたので下記はエラー
self.logger.debug("return value : %s", self.message["Message"][key]["Value"])
"""
# "Message"配下のStringを再度json形式で読み込む
msg_json = json.loads(self.message["Message"])
self.logger.debug("return value : %s", msg_json[key]["Value"])
return msg_json[key]["Value"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.