Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error verifying input, please try again." error #157

Open
hubacekjirka opened this issue Jun 22, 2018 · 7 comments
Open

"Error verifying input, please try again." error #157

hubacekjirka opened this issue Jun 22, 2018 · 7 comments

Comments

@hubacekjirka
Copy link

hubacekjirka commented Jun 22, 2018

After filling the form and getting a tick-mark on the recaptcha filed, I'm getting "Error verifying input, please try again." error message displayed in the widget after submitting.

My form class is:

class RegistrationForm(UserCreationForm):
	captcha = ReCaptchaField()

	class Meta:
		model = User
		fields = (
			'username',
			'email',
			'password1',
			'password2',
		)
		labels = { 'email': 'Email - just in case you need to reset your password'}
		

	def save(self, commit=True):
		user = super(RegistrationForm, self).save(commit=False)
		user.username = self.cleaned_data['username']
		user.email = self.cleaned_data['email']
		if commit:
			user.save()
		return user

Is there a way to further diagnose this issue?

@yvandermeer
Copy link

@hubacekjirka Same problem here, did you end up finding a solution?

@hubacekjirka
Copy link
Author

@yvandermeer Nope, still couldn't figure it out :(

@phala Could you please give us a clue what's going on? Many thanks!

@qcaron
Copy link

qcaron commented Jul 19, 2018

I added this code in fields.py:75:

import traceback
traceback.print_exc()

It gave me this:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/quentincaron/.virtualenvs/knbsb/lib/python3.6/site-packages/captcha/fields.py", line 72, in clean
    remoteip=self.get_remote_ip(), use_ssl=self.use_ssl)
  File "/Users/quentincaron/.virtualenvs/knbsb/lib/python3.6/site-packages/captcha/client.py", line 115, in submit
    httpresp = request(req)
  File "/Users/quentincaron/.virtualenvs/knbsb/lib/python3.6/site-packages/captcha/client.py", line 54, in request
    return urlopen(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

Locally it does not work but on the production version of the site it does because it uses HTTPS.

Adding the following in my local settings did not fix it:

RECAPTCHA_USE_SSL = False

@qcaron
Copy link

qcaron commented Jul 19, 2018

I fixed it by doing the following in my form class:

class MyForm(forms.ModelForm):
    captcha = ReCaptchaField()
    if getattr(settings, 'DEBUG', False):
        captcha.clean = lambda x: x[0]

This is based on what is returned by captcha.fields.ReCaptchaField.clean, lines 63 and 83.

@hubacekjirka
Copy link
Author

Just to summarize it, the server needs to be running HTTPS which might not be the case for the local dev server.

If the the web server isn't running HTTPS, the authenticity of the certificate can't be verified as there might be man-in-the-middle attack between the web server and client. In this case, the certificate verify failed error pops out:
[SSL: CERTIFICATE_VERIFY_FAILED]

The workaround for running captcha on the dev server without HTTPS is the one @qcaron suggests.

@shacker
Copy link

shacker commented Oct 20, 2018

Since pretty much all devs will encounter this, it would be nice if django-recaptcha could build this exception handling in. Thanks for the workaround @qcaron .

@alanverresen
Copy link
Contributor

I haven't encountered this problem yet, and I don't know how to reproduce this error, but when I search for the error [SSL: CERTIFICATE_VERIFY_FAILED], several older threads on StackOverflow pop up:

Based on these two posts, it mostly seems to affect MacOS, and still can affect recent versions of Python. So:

  • Is this a platform-specific problem?
    Does this only affect MacOS, or does this also affect other platforms?
  • Is this a problem that django-recaptcha should solve, or not?
    It seems like this is a "platform problem", but maybe an alternative solution exists that could be implemented by django-recaptcha?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants