Answer the question
In order to leave comments, you need to log in
Json.decoder.JSONDecodeError , I can't upload more than 2 pictures for a post to the VK group (vk api). How to be?
I want to make an auto-poster bot for the VK group ...
Below is the program code, I marked with a comment where the error is
def write_json(data,filename):
with open(filename,'w') as file:
json.dump(data,file,indent=2,ensure_ascii=False)
def get_upload_server():
r=requests.get('https://api.vk.com/method/photos.getWallUploadServer',params={
'access_token':token,
'group_id':GROUP_ID,
'v':ver,
}).json()
return r['response']['upload_url']
write_json(r,'upload_response.json')
def main():
upload_url=get_upload_server()
#ЗДЕСЬ ОШИБКА. Если файлов будет 2 или 1, то всё работает, если больше 2, то выдает ошибку
files={
'file1': open('IPAD1X.png','rb'),
'file2':open('Layer61X.png','rb'),
'file3':open('IphoneX.png','rb')}
upload_response=requests.post(upload_url,files=files).json()
write_json(upload_response,'upload_response.json')
result=requests.get('https://api.vk.com/method/photos.saveWallPhoto',params={
'access_token':token,
'group_id':GROUP_ID,
'server':upload_response['server'],
'photo':upload_response['photo'],
'hash':upload_response['hash'],
'v':ver,}).json()
Answer the question
In order to leave comments, you need to log in
I've been trying to fix it for 2 days
414 Request-URI Too Long
result=requests.post('https://api.vk.com/method/photos.saveWallPhoto', data={
'access_token':token,
'group_id':GROUP_ID,
'server':upload_response['server'],
'photo':upload_response['photo'],
'hash':upload_response['hash'],
'v':ver,}).json()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question