Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid-input-secret when using recaptcha in flask

Tags:

python

flask

I have a flask application, where i want to use recapchta in order to send an email.

I have made everything so far, and all seems to be working, however when i test the application on localhost, i get an error code back as a JSON response.

Here is the error code:

('JSON: ', {u'error-codes': [u'invalid-input-secret'], u'success': False})

So i have checked that the secret code is written correctly, and i even tried deleting it, and making a new one. But neither worked, i suspect, i might by the way that i write it in my code

NOTE! I'm not using WTForms (because it is not a login, just a simply mail API).

Here i how i have written my configuration:

app.config.update({'RECAPTCHA_ENABLED': True,
               'RECAPTCHA_SITE_KEY':
                   '6Ldj2GcUAAAAAA7MuBOKsDRIk1fMLvNaGBtrB7Du',
               'RECAPTCHA_SECRET_KEY':
                   '(secret key is written here correctly)'})

Does anybody know why i keep getting this error?

Should i put the keys in a config.py file?

like image 513
Dedi Avatar asked Nov 30 '25 19:11

Dedi


1 Answers

Okay so I found a way to make it work, but I do not think this is the optimal solutions (comments or other answers are very welcome), I put my secret-key directly in the method like so:

    r = requests.post('https://www.google.com/recaptcha/api/siteverify',
                      data = {'secret' :
                              'secret-key inserted here directly',
                              'response' :
                              request.form['g-recaptcha-response']})
google_response = json.loads(r.text)
print('JSON: ', google_response)

I think this might not be an optimal reason for security reasons, I think it should be stored as a variable first, however, I have tried some different configurations, and it did not work.

like image 142
Dedi Avatar answered Dec 02 '25 08:12

Dedi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!