python 3.x - When I tried to get json structure I got this "TypeError: list indices must be integers or slices, not dict" -


i calling api code got error when tried json structure got error:

file "<ipython-input-8-59af996ee581>", line 12, in result = results[result_id]

typeerror: list indices must integers or slices, not dict

from client import restclient  client = restclient("jxxxxxx@xxxx.com", "xxxxxxxyyyyy") completed_tasks_response = client.get("/v2/srp_tasks_get") if completed_tasks_response["status"] == "error":     print("error. code: %d message: %s" % (completed_tasks_response["error"]["code"], completed_tasks_response["error"]["message"])) else:     results = completed_tasks_response["results"]     print(results)     result_id in results:         result = results[result_id]         srp_response = client.get("/v2/srp_tasks_get/%d" % (result["142657080"]))         if srp_response["status"] == "error":             print("error. code: %d message: %s" % (srp_response["error"]["code"], srp_response["error"]["message"]))         else:             print(srp_response["results"]) 

you don't show json trying parse (why?), but, error says, results list of dictionaries , not integers, doesn't seem expected be.

you should either:

iterate on result dictionaries results contains:

for result in results:         srp_response = client.get("/v2/srp_tasks_get/%d" % (result["142657080"]))         ... 

or make sure using api correctly.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -