D
D
dimaaksenov062018-08-09 09:32:01
Python
dimaaksenov06, 2018-08-09 09:32:01

Incomprehensible vk_api error?

After fixing one error, a second appeared on line 17: values['last_message_id'] = response['items'][0]['id']
KeyError: 'id'
Code:
import vk_api
import time
vk = vk_api.VkApi(token= 'e9ae13d9f73319...')
vk._auth_token()
values ​​= {'out': 0, 'count': 100, 'time_offset': 60}
vk.method('messages.getConversations', values)
def write_msg(user_id, s):
vk.method('messages.send', {'user_id':user_id, 'messages':s})
while True:
response = vk.method('messages.getConversations', values)
if response['items' ]:
values['last_message_id'] = response['items'][0]['id']
for item in response['items']:
write_msg(item['user_id'], 'Hello artist!')
time.sleep(1)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Michurin, 2018-08-09
@denistu10

In response['items'][0]['id'] there is no id key, most likely there is already not a list, but just a sheet

H
Helow19274, 2018-08-09
@Helow19274

When specifying a token, you do not need to log in at all. remove _auth_token()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question