When the entered key is equal to the captcha text, I consistent get the following exception: raise Recaptcha Invalid Challenge Error(challenge id). This is my backend script validation:
recaptcha_client = RecaptchaClient('6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe', '6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF&hl')
try:
is_solution_correct = recaptcha_client.is_solution_correct(
str(request.POST["recaptcha_response_field"]),
str(request.POST["recaptcha_challenge_field"]),
'127.0.0.1',
)
except RecaptchaUnreachableError as exc:
print exc.message
except RecaptchaException as exc:
print exc.message
else:
if is_solution_correct:
print('it works')
else:
print('captcha error')
This is the part of template script reserved for the captcha input:
<script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF&hl=en"></script>
<noscript>
<iframe src="https://www.google.com/recaptcha/api/noscript?k=6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF&hl=fr" height="300" width="500" frameborder="0"></iframe><br />
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
</noscript>