Пожалуйста, помогите решить проблему.
Я отправляю post запрос серверу, который возвращает мне ответ json формате.
Этот ответ я записываю в файл для последующей обработки:
Запрос к серверу:
import json
import requests
myurl = "http://....................."
response = requests.post(myurl, auth = ("xyz", "xyz"))
json_text = response.text
print(json_text)
with open("json_resp.txt", "w") as file:
file.write(json.dumps(json_text))
полученный файл:
{
"query": {
"msisdn": {
"ton": 1,
"npi": 1,
"address": "123456789"
},
"sm-RP-PRI": false,
"serviceCentreAddress": {
"ton": 1,
"npi": 1,
"address": "123456789"
}
},
"timeout": true,
"sccp-info": {
"sccp-remote-address": {
"ai": {
"global-title-indicator": 4,
"routing-indicator-bit": false,
"national-reserved-bit": false,
"point-code-indicator": false,
"sub-system-indicator": true
},
"ssn": 6,
"tt": 0,
"nai": 4,
"npi": 1,
"address": "123456789"
},
"sccp-local-address": {
"ai": {
"global-title-indicator": 4,
"routing-indicator-bit": false,
"national-reserved-bit": false,
"point-code-indicator": false,
"sub-system-indicator": true
},
"ssn": 8,
"tt": 0,
"nai": 4,
"npi": 1,
"address": "123456789"
}
},
"user-identifier": "M00000051",
"map-dialog-id": "D00000051",
"billing-info": {
"billed": "0.010000",
"credits": 99991.55
},
"link": "3000"
}обработка ответа от сервеа:
import json
file = open("json_resp.txt").read()
parse_input = json.loads(file)
query = parse_input["query"]
и тут сразу же получаю ошибку:
query = parse_input
TypeError: string indices must be integers
помогите понять, причину ошибки и как правильно подходить у ее решению.
Заранее Всем спасибо!