W
W
Worgen2018-10-20 21:51:37
Python
Worgen, 2018-10-20 21:51:37

How to upload images to posts via vk_api?

Good afternoon, I can't upload an image to pythonanywhere, although everything is ok on the local machine. Writes the following error

Traceback (most recent call last):
  File "test.py", line 140, in <module>
    whoSend()
  File "test.py", line 126, in whoSend
    userSend(event.user_id)
  File "test.py", line 101, in userSend
    if None != readMessage(event.text):
  File "test.py", line 92, in readMessage
    photo = upload.photo_messages(photos=image.raw)[0]
  File "/home/Worgen/.local/lib/python2.7/site-packages/vk_api/upload.py", line 82, in photo_messages
    return self.vk.method('photos.saveMessagesPhoto', response.json())
  File "/home/Worgen/.local/lib/python2.7/site-packages/vk_api/vk_api.py", line 615, in method
    raise error
vk_api.exceptions.ApiError: [1] Unknown error occurred

Function code
image = session.get('http://urtt.ru/phphtml/docs/zamen.jpg', stream=True)
        photo = upload.photo_messages(photos=image.raw)[0]
        return None,'photo{}_{}'.format(photo['owner_id'], photo['id'])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SD4RK, 2018-10-21
@SD4RK

The link should be with the HTTPS protocol, the easiest way is to upload a photo to VK and get a link to the photo through the element code so that the link looks something like this " https://pp.userapi.com/.../.../xxx. jpg ", and paste it into the code, in theory, everything should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question