Use reCAPTCHA v3 with Flask


a simple HTML form with grecaptcha:

  • the script will call grecaptcha to fetch a reponse,
  • the respone will be sent together with the form so that backend can verify the grecaptcha response.
    <script src="{reCAPTCHA_site_key}"></script>

        grecaptcha.ready(function () {
            grecaptcha.execute('{reCAPTCHA_site_key}', {action: 'validate_captcha'}).then(function (token) {
      "got token: " + token);
                document.getElementById('g-recaptcha-response').value = token;

    <input name="email" type="email">

    <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
    <input type="hidden" name="action" value="validate_captcha">
    <input type="submit" class="btn btn-primary" value="Generate RSS"/>



a simple http call to veify the grecaptcha response sent by frontend:

@app.route('/handle', methods=["POST"])
def lists():
    parameters = request.form

    recaptcha_passed = False
    recaptcha_response = parameters.get('g-recaptcha-response')
        recaptcha_secret = os.environ.get('RECAPTCHA_SECRET')
        response ='{recaptcha_secret}&response={recaptcha_response}').json()
        recaptcha_passed = response.get('success')
    except Exception as e:
        print(f"failed to get reCaptcha: {e}")
- 2020-05-17 edit