Answer the question
In order to leave comments, you need to log in
How to enter captcha through a bot in Python?
I am writing a bot for VK in python, I logged in through my account (through a user, roughly speaking) there was a problem when the bot sends a lot of messages, it gives me an error, specifically:
raise captcha vk_api.exceptions.Captcha: Captcha needed
Answer the question
In order to leave comments, you need to log in
https://vk.com/dev/captcha_error
If this error occurs, then the following parameters are also transmitted in the error message:
captcha_sid - captcha identifier
captcha_img - link to the image to be shown to the user so that he enters the text from this image.
In this case, you should ask the user to enter the text from the captcha_img image and repeat the request, adding the following parameters to it:
captcha_sid - received identifier
captcha_key - text entered by the user
If you work with api (i.e. plain text captcha), then something like this:
The library is base64, it will convert the image to base64 itself (there will be a link to the captcha in the answer)
отправка на рукапчу:
image = base64.encodebytes(res.content)
url = 'https://rucaptcha.com/in.php'
params = dict(key=rucaptcha, method='base64', body=image, json=1)
res = requests.post(url, params)
чек ответа:
url = 'https://rucaptcha.com/res.php'
params = dict(key=rucaptcha, action='get', id=res.json()['request'], json=1)
while True:
sleep(3)
res = requests.get(url, params)
if int(res.json()['status']) == 1:
# тут делать, что нужно, т.е. повторно отправлять запрос с решенной капчей
# решенная капча в res.json()['request']
url = 'https://api.vk.com/method/wall.post'
params = dict(v=5.124, access_token=API_KEY, message='123',
captcha_sid=capthca_sid, captcha_key=res.json()['request'])
res = requests.get(url, params=params)
break
elif res.json() == 'CAPCHA_NOT_READY':
continue
else:
print('ERROR')
print(res.json())
break
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question