Answer the question
In order to leave comments, you need to log in
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
In response['items'][0]['id'] there is no id key, most likely there is already not a list, but just a sheet
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 questionAsk a Question
731 491 924 answers to any question