N
N
Nikita Roschenko2015-08-24 18:12:54
Python
Nikita Roschenko, 2015-08-24 18:12:54

Why does 129 error appear when uploading a photo via vk api?

Good afternoon, there is a task to update a profile photo through a Python script.
To speed up work with api vk, I use this library: https://github.com/python273/vk_api
Here is the code:

from vk_api import *

vk = VkApi('login', 'password')
vk.authorization()

url = vk.method('photos.getOwnerPhotoUploadServer', {})['upload_url']

photos = ['1.jpg']

photos_files = open_photos(photos)
response = vk.http.post(url, files=photos_files).json()
close_photos(photos_files)

print vk.method('photos.saveOwnerPhoto', {
            'server': response['server'],
            'hash': response['hash'],
            'photo': response['photo'],
})

And when calling the 'photos.saveOwnerPhoto' method, I get an error:
File "/home/nikita/PycharmProjects/django/upload_photo.py", line 39, in handle
    self.photo('1.jpg')
  File "/home/nikita/PycharmProjects/django/upload_photo.py", line 29, in photo
    print self.vk.method('photos.saveOwnerPhoto', values)
  File "/usr/local/lib/python2.7/dist-packages/vk_api/vk_api.py", line 373, in method
    raise error
vk_api.vk_api.ApiError: [129] Invalid photo: no "file" file, from upl_625624?act=owner_photo

I can not understand what the problem is, do not tell me what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xozzslip, 2015-08-25
@xozzslip

When an error occurs when calling a method, it comes instead response, errorand this field has a error["error_msg"], in which everything is written.
Try in some api method, right on the method page, call it with a deliberately incorrect input, you will understand what I mean.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question