T
T
timur kup2020-09-03 21:01:54
Python
timur kup, 2020-09-03 21:01:54

KeyError: 'response' in vk_api?

Hello again. So I wrote an autostatus that displays likes from Ava in the status.
And error: 5f512f0682da6031789393.png
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)

Please help, why does it show an error about response when it should?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timur Pokrovsky, 2020-09-03
@timur_ffsdfdsf

try to output getLikes

A
Anthony228357, 2020-09-03
@Anthony228357

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.

F
FrozenHome, 2020-09-04
@FrozenHome

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 question

Ask a Question

731 491 924 answers to any question