Django REST Framework with a password reset form - not working when hosted in render.com

86 views Asked by At

I am creating a mobile application for my university project and also a backend for the application. I used the default DRF password reset functions and built a template form for the user to reset their password. Everything works when unit testing and also in localhost. But when I host it in render.com it does not seem to work. Earlier it kept giving bad request (502) error and I kept to fix it later. Now it keeps giving 'Worker (pid:43) was sent SIGKILL! Perhaps out of memory?' and I have no idea how to fix.

I added comments to identify what's happening and the function is as follows.

def passwordReset(request, token):
    if request.method == 'POST':
        #test print
        print('==============================PASSWORD RESET START==============================')
        form = PasswordForm(request.POST)
        reset_password_url = "{}://{}/api/password_reset/confirm/".format(request.scheme, request.get_host())
        data = {"password": request.POST.get('password'), "token": token}
        #test print
        print(data['password'])
        print(data['token'])
        print(reset_password_url)
        try:
            response = requests.post(reset_password_url, json=data)
            #test print
            print("Response code : "+str(response.status_code))
            if response.status_code == 200:
                #test print
                print('==============================PASSWORD RESET END 200==============================')
                return render(request, 'api/password_reset_response.html', {'status':200})
                
            if response.status_code == 400:
                form.errors['password'] = response.json()['password']
                #test print
                print('==============================PASSWORD RESET END 400==============================')
                return render(request, 'api/password_reset_form.html', {'form': form})
            if response.status_code == 404:
                #test print
                print('==============================PASSWORD RESET END 404==============================')
                return render(request, 'api/password_reset_response.html', {'status':404})
            
            #test print
            print('==============================PASSWORD RESET END UNIDTFD==============================')
            return render(request, 'api/password_reset_response.html', {'error': 'Something went wrong. Please try again.'})
        except Exception as e:
            #test print
            print('==============================PASSWORD RESET ERR=============================='+e)
            return render(request, 'api/password_reset_response.html', {'error':e})

    if request.method == 'GET':
        form = PasswordForm(initial={'token': token})
        return render(request, 'api/password_reset_form.html', {'form': form})

Given below is what I see in the console


Oct 31 05:33:42 PM ==============================PASSWORD RESET START==============================

Oct 31 05:33:42 PM ;lkjhg6790

Oct 31 05:33:42 PM 57664679f9103f58d06ca2b7d0bdd8c98e585a355fa

Oct 31 05:33:42 PM https://domain.onrender.com/api/password_reset/confirm/

Oct 31 05:33:44 PM [2023-10-31 08:33:44 +0000] [41] [ERROR] Worker (pid:43) was sent SIGKILL! Perhaps out of memory?

Oct 31 05:33:44 PM [2023-10-31 08:33:44 +0000] [44] [INFO] Booting worker with pid: 44

Oct 31 05:33:47 PM 127.0.0.1 - - [31/Oct/2023:08:33:47 +0000] "POST /api/password_reset/confirm/ HTTP/1.1" 200 15 "-" "python-requests/2.31.0"


When it gave the bad request error it used to print 502 error code after the domain name link

Please help if you know anything. I am planning to host this later in AWS so need to fix the issues before making the payments otherwise it could be in vain.

I tried adding the comments to identify the exact issue, googled a lot but no luck.

0

There are 0 answers