证书验证由于重新验证而失败

时间:2019-04-03 08:56:07

标签: python-3.x recaptcha flask-wtforms

我为我的WTForms注册了Recaptcha,并且此错误**

  

SSL:弹出CERTIFICATE_VERIFY_FAILED

我提交表单时。

我通过label = localhostdomains = localhost and 127.0.0.1在Google上注册了Recaptcha

当我确认自己不是机器人后提交表单时,我被重定向到页面,并出现以下错误:

  

urllib.error.URLError urllib.error.URLError:   urlopen错误[SSL:   CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:777)

如果我将app.config['TESTING']设置为 True ,则表单可以很好地提交。

这是我的app.py的样子:

from flask import Flask, render_template
from flask_wtf import FlaskForm, RecaptchaField                                                                        
from wtforms import StringField, PasswordField                                                                         
from wtforms.validators import InputRequired, Length, AnyOf                                                             

app = Flask(__name__)
app.config['SECRET_KEY'] = 'Thisissecret!'
app.config['RECAPTCHA_PUBLIC_KEY'] = '6LdUxpsUAAAAAEKf7HmevAB9-ntHArEovS2pDmOP'
app.config['RECAPTCHA_PRIVATE_KEY'] = '6LdUxpsUAAAAACtXnVVOYTX1M9Hv83jkhzx4KxX1'
app.config['TESTING'] = False                                                                                           

class LoginForm(FlaskForm):                                                                                            
    username = StringField('username', validators=[InputRequired(message='A username is required!'), Length(min=5, max=10, message='Must be between 5 and 10 characters')])                     
    password = PasswordField('password', validators=[InputRequired(message='Password is required!'), AnyOf(values=['password', 'secret'])])                                                     
    recaptcha = RecaptchaField()

@app.route('/form', methods=['GET', 'POST'])
def form():
    form = LoginForm()

    if form.validate_on_submit():                                                                                       
        return '<h1>The username is {}. The password is {}.</h1>'.format(form.username.data, form.password.data)
    return render_template('form.html', form=form)                                                                     

if __name__ == '__main__':
    app.run(debug=True)

在我的form.html中,我在正文部分添加了{{ form.recaptcha }}

我希望重新验证验证后,表单可以提交。

0 个答案:

没有答案