This is what I get the message history and when I try to parse the json error shows me:

Traceback (most recent call last): File "D:/vk_api/venv/gg.py", line 11, in <module> message = response['items'][0]['body'] KeyError: 'items' 

Here is the code:

 import requests from data import VkData response = requests.get(VkData.api_url + 'messages.getHistory?access_token=' + VkData.token + '&v=5.52', {'user_id': VkData.user_id, 'count': 1}) result = response.text import json response = json.loads(result) message = response['items'][0]['body'] print(message) 

Parsya of this:

 {"response":{"count":1201,"items":[{"id":8331,"body":"1","user_id":251343550,"from_id":409705263,"date":1534601051,"read_state":0,"out":1,"random_id":1199328298}],"in_read":8331,"out_read":8263}} 

HELP

  • response no items key. Most likely it should be like this response['response']['items'][0]['body'] - ArchDemon
  • Yes, thanks a lot helped! - Andrey Gomonov

0