Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm trying to get my code to give me information based on the id the user inputs.
For some reason I get the print corresponding with TypeError even though I input the correct number that does have data.
What's going on?

What I have tried:

This is my code:
Python
from django.shortcuts import render, HttpResponse
import requests
from django.views.generic import FormView
from .forms import MonotributoForm
from app.ws_sr_padron import get_persona

class ConstanciaInscripcion(FormView):

    def get(self, request):
       return render(request, 'app/constancia-inscripcion.html')
    
    def post(self,request):

        form = MonotributoForm(request.POST)
            
        try:
           cuit_r = int(request.POST.get('cuit', '-1'))  # Get 'cuit' with default of -1
        except ValueError:
           print('try again')

        response =get_persona(cuit_r)

        try:
            nombre = response["persona"]["nombre"]
            apellido = response["persona"]["apellido"]
        except KeyError:
            nombre, apellido = None, None
            print("response is missing keys!")
        except TypeError:
            nombre, apellido = None, None
            print("response had wrong type!")
        else:
            print("nombre:", nombre)
            print("apellido:", apellido)

        if form.is_valid():
            cuit = form.cleaned_data.get('cuit')
            email = form.cleaned_data.get('email')
            cuit.save()
            email.save()
            return HttpResponseRedirect('app/constancia-inscripcion.html')


        return render(request, 'app/constancia-inscripcion.html')
Posted
Comments
Richard MacCutchan 5-Mar-21 5:20am    
Where does the error occur? What are the values of the variables that raise the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900