D
D
dr_mamaev2018-01-27 19:38:57
Python
dr_mamaev, 2018-01-27 19:38:57

Error in POST request VK api python, what is wrong?

Gives error 22, what's wrong?

import vk,requests,json

session = vk.Session(access_token='здесь_токен')
api = vk.API(session)

uid=str(2000000000+519)

upload_url=(api.photos.getChatUploadServer(chat_id=str(uid),crop_x='648',crop_y='0',crop_width='400'))['upload_url']
print (upload_url) #получили ссылку для загрузки
f = {'file': str(open('photo.jpg', 'rb'))} #подготовка картинки для загрузки
upload_serv=requests.post(upload_url,files=f).json() #загрузка на сервер
print(upload_serv) #пишет ошибку vk.exceptions.VkAPIError: 22. Upload error: bad format «file» file
api.messages.setChatPhoto(file=upload_serv['response']) #по идее, это сохранение
f.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
David Chuck, 2018-05-11
@Chaki09

Try sending the image directly without wrapping it in a json construct:
f = str(open('photo.jpg', 'rb'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question