N
N
Nikita karpov2022-03-19 12:23:02
Python
Nikita karpov, 2022-03-19 12:23:02

How to fix error code 1 vk_api?

Good day, I'm trying to put a large amount of pictures on the page through VK api, I do everything with the help of this code:

import vk
import sys

session = vk.Session(access_token ="")
vk_a = vk.API(session , v= '5.92', lang = 'ru')


    # Список с ссылками на картинки
hrefs = [
    r'C:\Users\Никита\Pictures\4K Stogram\dariarebeshchenko\1970-01-01 03.00.00 .jpg',
]

for href in hrefs:
    vk_a.wall.post(attachments = hrefs , message = '1' , owner_id = '')


In response I get error 1
Traceback (most recent call last):
  File "main.py", line 14, in <module>
    vk_a.wall.post(attachments = hrefs , message = '1' , owner_id = '')
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python36\lib\site-packages\vk\api.py", line 173, in __call__
    return self._api._session.make_request(self)
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python36\lib\site-packages\vk\api.py", line 102, in make_request
    raise error
vk.exceptions.VkAPIError: 1. Unknown error occurred. request_params = {'method': 'wall.post', 'oauth': '1', 'v': '5.92', 'lang': 'ru', 'attachments': 'C:\\Users\\Никита\\Pictures\\4K Stogram\\dariarebeshchenko\\1970-01-01 03.00.00 .jpg', 'message': '1', 'owner_id': ''}

Found what the error means. VK itself does not write anything sensible about the error
6235a0e365a41745373405.png

Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-03-19
@SoreMix

Absolutely wrong method of sending images.
1. wall.post accepts lines of the form in the attachments field <type><owner_id>_<media_id>, but not the path to the file on the PC
https://dev.vk.com/method/wall.post
2. First, the images must be uploaded to the VK server. Or look at the examples in the library, all of a sudden there are loading methods there, but in the general case this is done like this:

  1. We get the server address for uploading using the photos.getWallUploadServer method
  2. VK will return upload_url, to which you will need to send an image of type multipart/form-dataPOST by the method, again, if the library has its own methods of sending, send through it, if not, then somerequests
  3. After a successful download, VK will return server, hash, photo
  4. Then the photos.saveWallPhoto method is called, where the data from the paragraph above is transferred to the appropriate fields
  5. If successful, VK will return the photo object from which the owner_id and media_id are needed
  6. We take them and do vk_a.wall.post(attachments = 'photoOWNERID_MEDIAID' , message = '1' , owner_id = '')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question