1
votes

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>
1

1 Answers

2
votes

Looking at your RecaptchaClient and your template script, it appears that your public key in the RecaptchaClient is incorrect.

Here is the script source:

https://www.google.com/recaptcha/api/challenge?k=6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF&hl=en

This link contains two parameters:

  • k=6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF
  • hl=en

The public key in your RecaptchaClient includes the "&hl" from the next parameter after the key.

recaptcha_client = RecaptchaClient('6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe', '6LeuNO4SAAAAAAdkaCUi6ybtISPI-YhIlOadgFNF')