Catch and handle recaptcha API errors

Just send the user an API error and they can try again. Better than
internal server error + email to webmaster... Seems to be caused by
intermittent network issues.
This commit is contained in:
Magnus Hagander
2016-11-14 18:53:10 +01:00
parent caf152eb62
commit c5d162dee7

View File

@ -57,10 +57,16 @@ class ReCaptchaField(forms.CharField):
# if self.remoteip:
# param['remoteip'] = self.remoteip
c.request('POST', '/recaptcha/api/siteverify', urllib.urlencode(param), {
'Content-type': 'application/x-www-form-urlencoded',
})
c.sock.settimeout(10)
try:
c.request('POST', '/recaptcha/api/siteverify', urllib.urlencode(param), {
'Content-type': 'application/x-www-form-urlencoded',
})
c.sock.settimeout(10)
except Exception, e:
# Error to connect at TCP level
log.error('Failed to connect to google recaptcha API: %s' % e)
raise ValidationError('Failed in API call to google recaptcha')
try:
r = c.getresponse()
except: