Answer the question
In order to leave comments, you need to log in
KeyError: 'response' in vk_api?
Hello again. So I wrote an autostatus that displays likes from Ava in the status.
And error:
Code:
import requests
import time
token = "my_token" #Сюда вводим свой токен.
timeKD = 60 #Сюда вводим время обновления статуса.(Время в секундах)
def startStatus():
try:
getLikes = requests.get("https://api.vk.com/method/photos.get?album_id=profile&rev=1&extended=1&count=1&v=5.95&access_token={token}").json()
getLikes = getLikes["response"]["items"][0]["likes"]["count"]
except IndexError:
print("У профиля отсутствует аватар или лайки.")
getLikes = 0
statusSave = (" | Лайков на аве: " + getLikes)
statusOut = requests.get("https://api.vk.com/method/status.set?text={statusSave}&v=5.95&access_token={token}").json()
while True:
startStatus()
time.sleep(timeKD)
Answer the question
In order to leave comments, you need to log in
Most likely, the error says that there is no response field in the json response, try to output json to the console and the sequence is already looking there.
Because it's Python. it can shorten json request format from vk.
Try replacing: getLikes = getLikes["response"]["items"][0]["likes"]["count"]
with: getLikes = getLikes["items"][0]["likes"]["count "]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question