0

*I implemented Google's reCAPTCHA to my site with the django-recaptcha plugin. All works well. But when I validate the captcha and launch the form I get this error <urlopen error [Errno 11001] getaddrinfo failed>.

I would like to know how to interpret it and display a correct message to the user. Thanks in advance.*


here is the error:
URLError at /connexion/
<urlopen error [Errno 11001] getaddrinfo failed>
Request Method: POST
Request URL:    http://127.0.0.1:8000/connexion/
Django Version: 4.1.2
Exception Type: URLError
Exception Value:    
<urlopen error [Errno 11001] getaddrinfo failed>
Exception Location: C:\Python310\lib\urllib\request.py, line 1351, in do_open
Raised during:  connexion.views.index_connexion
Python Executable:  C:\Users\User\Documents\Travail\sms-chapchap-2022\env\Scripts\python.exe
Python Version: 3.10.4
Python Path:    
['C:\\Users\\User\\Documents\\Travail\\sms-chapchap-2022\\src',
 'C:\\Python310\\python310.zip',
 'C:\\Python310\\DLLs',
 'C:\\Python310\\lib',
 'C:\\Python310',
 'C:\\Users\\User\\Documents\\Travail\\sms-chapchap-2022\\env',
 'C:\\Users\\User\\Documents\\Travail\\sms-chapchap-2022\\env\\lib\\site-packages']
Server time:    Fri, 18 Nov 2022 16:19:54 +0000

Connexion.Views :

def index_connexion(request):
    if request.user.is_authenticated:
        return redirect('index_accueil')
    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        email = request.POST['email']
        password = request.POST['password']
        user = auth.authenticate(email=email, password=password)
        if form.is_valid():
            if user is not None:
                if user.is_active:
                    auth.login(request, user)
                    return JsonResponse(True, safe=False)
                else:
                    messages.error(request, 'Votre compte n\'est pas activé, consultez vos Email!!')
                    return JsonResponse(False, safe=False)
            else:
                messages.error(request, 'Email ou mot de passe invalide!')
                return JsonResponse(False, safe=False)
        else:
            for key, error in list(form.errors.items()):
                if key == 'captcha':
                    messages.error(request, "Vous devez réussir le test reCAPTCHA")
                    return JsonResponse(False, safe=False)

    form = UserLoginForm()
    return render(request, "connexion/connexion.html", {"connexion": 1, "form": form})

Connexion.Form:

from django import forms
from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV2Checkbox


class UserLoginForm(forms.Form):

    captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox())

0 Answers0