在python中解析har文件时出现TypeError

时间:2017-09-24 10:10:42

标签: json python-3.x typeerror

我在使用json解析python中的har文件时遇到错误“TypeError:string indices必须是整数”。这是我的代码:

f = open(sys.argv[1], 'r', encoding = "utf8")
global data
data = json.load(f)
f.close()
entries = data["log"]["entries"]

for entry in entries:
url = urlparse(entry["request"]["url"])
domain = url.netloc 
entry["domain_name"] = domain
if domain in domain_dict:
    domain_dict[domain].extend(entry)
else:
    domain_dict[domain] = [entry]

for dom in domain_dict:
    for y in domain_dict[dom]:
        url_temp = y["request"]["url"]
        filetype = y["response"]["content"]["mimeType"]

我在行

中收到错误“TypeError:string indices必须是整数”
url_temp = y["request"]["url"]

错误不会出现在循环的每次迭代中。

0 个答案:

没有答案