reCAPTCHA始终返回不正确的CAPTCHA

2024-06-13 07:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在pythonweb应用程序中验证reCAPTCHA,但是我总是得到incorrect-captcha-sol错误,尽管响应是正确的。以下是验证代码:

data = {
    'privatekey': config.registry.settings['captcha_private_key'],
    'remoteip': ip,
    'challenge': challenge,
    'response': response,
}
request = urllib2.Request('http://www.google.com/recaptcha/api/verify',
                          urllib.urlencode(data))
response = urllib2.urlopen(request)
if response.readline() != 'true':
    log.error('Captcha validation error, error_code=%s' % (response.readline()))
    raise httpexceptions.HTTPUnauthorized()

为了获得质询和响应值,我使用get_challenge()和{}javascript函数,然后通过AJAX发送这些值。在


Tags: 代码应用程序datareadlineresponserequest错误error