0

I have a script in Python that helps me to post some notes in VK. But sometimes my script needs to solve captcha. I have following code:

vk = vkontakte.API(token=token)
response = vk.wall.repost(object = link)

As I understand, if I need to solve captcha, VK API raises exception. But, I couldn't find any examples for it. Problem is that I can't get captcha_sid and captcha_img from it.

Or maybe you know how can I get response in JSON format, not as exception ?

perror
  • 7,071
  • 16
  • 58
  • 85
H. Potter
  • 1
  • 1
  • 3

2 Answers2

0

You can access vk api via http requests. For doing this you need access_token, read here how to get it if you dont have it already.

Then you way will be very easy by link

https://api.vk.com/method/wall.repost?object=WALL_OBJECT_HERE&group_id=TARGET_GROUP_ID&access_token=YOUR_ACCESS_TOKEN

If repost done successfully, you will see response like this:

{"response":{"success":1,"post_id":676,"reposts_count":3,"likes_count":11}}

But if you need to solve captcha response will be like this:

{"error":{"error_code":14,"error_msg":"Captcha needed","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"wall.repost"},{"key":"object","value":"your_object_here"},{"key":"group_id","value":"56983001"}],"captcha_sid":"381041951450","captcha_img":"http:\/\/api.vk.com\/captcha.php?sid=381041951450&s=1"}}

Now you can easily get captcha sid and captcha_img link, download it, solve and repeat request upper just with adding 2 parameters to it: captcha_key=YOUR_SOLVED_CAPTCHA&captcha_sid=SID_YOU_GOT

Success :)

Community
  • 1
  • 1
SwiftStudier
  • 2,272
  • 5
  • 21
  • 43
0

First, make sure you have the last stable version of vkapi

However, in the old ones when you receive VKError, the captcha_img and captcha_sid are keys to .error, not to the Exception itself:

except vkerror as e:
    captcha_img = e.error['captcha_img']
    captcha_sid = e.error['captcha_sid']

Just make sure you've defined the right Error:

vkapi = vk.API(access_token=ACCESS_TOKEN)
vkerror = vk.api.VkAPIMethodError  # not vk.API (still it has the same Exception in it)
L. Fox
  • 31
  • 5