D
D
danis_20142017-02-26 18:27:55
Python
danis_2014, 2017-02-26 18:27:55

How to solve the problem with loading captcha?

You need to upload the captcha image to the rucaptcha service and get the captcha text itself. The documentation for uploading images says:

Пример загрузки в формате multipart:
<form method="post" action="http://rucaptcha.com/in.php" enctype="multipart/form-data">
<input type="hidden" name="method" value="post">
Ключ от учетной записи:
<input type="text" name="key" value="YOUR_APIKEY">
Файл капчи:
<input type="file" name="file">
<input type="submit" value="загрузить и получить ID">
</form>

The documentation for the Requests library says:
# POST a Multipart-Encoded File
url = 'http://httpbin.org/post'
files = {'file': open('report.xls', 'rb')}
r = requests.post(url, files=files)

I get this code:
key = 'mykey'
file = {'file': open('captcha.jpg', mode='rb')}  # captcha.jpg - изображение с капчей
r = requests.post('http://rucaptcha.com/in.php', files=file, data={'key': key})  # OK|captchaid
id = r.text.split('|')[1]
inspect = 'CAPCHA_NOT_READY'
while inspect == 'CAPCHA_NOT_READY':
    r2 = requests.get('http://rucaptcha.com/res.php?key='+key+'&action=get&id='+id) 
    inspect = r2.text

If the captcha text is not ready yet, then r2.text will be equal to 'CAPCHA_NOT_READY', otherwise r2.text will be equal to the captcha text. That is, the last cycle is executed until the captcha is ready. But the problem is that this cycle does not end. That is, the response is always "CAPCHA_NOT_READY". Any ideas why this is happening?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
danis_2014, 2017-03-01
@danis_2014

The problem was in setting up a rucaptcha account

D
Dimonchik, 2017-02-28
@dimonchik2013

where do you get the code from?
while how it works - know?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question