Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question