TypeError: 'Personalinfo' object is not iterable

Hello, am using a reportlab to generate PDF report for the user after submitting his information. But this error occurs. I dont know what am doing wrong please i need help to move on.

views

  def general_pdf(request, id):
      #generate bytestream buffer
      buf = io.BytesIO()
      #create a canvas
      c =canvas.Canvas(buf, pagesize=letter, bottomup=0)
      # create a text object
      textobj = c.beginText()
      textobj.setTextOrigin(inch, inch)
      textobj.setFont('Helvetica', 14)
      # design the model
      
      persons =Personalinfo.objects.get(user_id =id)
      
      # create blank list
      lines =[]
      for person in persons:
          lines.append(person.first_name)
          lines.append(person.second_name)
          lines.append(person.gender)
          lines.append(person.marital_status)
          lines.append(person.date_of_birth)
          lines.append(person.job)
          lines.append(person.course_of_study)
          lines.append(person.contact_address)
          lines.append(person.passport)
          lines.append(person.phone)
          lines.append(person.state)
          lines.append(person.lga)
     
      #loop
      for line in lines:
          textobj.textLine(line)
      #finish up
      c.drawText(textobj)
      c.showPage()
      c.save()
      buf.seek(0)
      return FileResponse(buf, as_attachment=True, filename='CSC.pdf')

the models

class Personalinfo(models.Model):
    user=models.ForeignKey(User, null=True, on_delete=models.CASCADE)
    first_name =models.CharField(max_length=100, null=True)
    second_name =models.CharField(max_length=100, null=True)
    gender=models.CharField(choices=CHOICE_FIELD, max_length=10, null=True)
    marital_status = models.CharField(choices=MARITAL_CHOICES, max_length=100, null=True)
    date_of_birth =models.DateField(null =True)
    job = models.ForeignKey(Job, on_delete=models.CASCADE, null=True, related_name='persoalinfo')
    course_of_study=models.CharField(max_length=100, null=True)
    contact_address =models.CharField(max_length=300, null=True)
    passport = models.ImageField(upload_to='', null=True)
    phone= models.CharField(max_length=15, null=True)
    state =models.CharField(choices=STATE_CHOICES, max_length=10, null=True)
    lga =models.CharField(max_length=10, null=True)

the Traceback

System check identified no issues (0 silenced).
November 18, 2022 - 12:27:58
Django version 4.0, using settings 'adamawa_civil_service_recruitment.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /general_pdf/2/
Traceback (most recent call last):
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Christopher\adamawa_civil_service_recruitment\portal\views.py", line 125, in general_pdf
    for person in persons:
TypeError: 'Personalinfo' object is not iterable
[18/Nov/2022 12:29:39] "GET /general_pdf/2/ HTTP/1.1" 500 63497

How many Personalinfo objects are you going to retrieve with this query?

More specifically, what is the data type of persons as a result of this query?

(If necessary, see the docs for get and Retrieving objects.)

I want a user to print the form that he submitted. when i use filter as follows

persons =Personalinfo.objects.filter(user_id =id)

i get the following runtimenerro

RuntimeError: unexpected exception in unicode2T1 @ src\rl_addons\rl_accel\_rl_accel.c:634

Traceback (most recent call last):
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Christopher\adamawa_civil_service_recruitment\portal\views.py", line 141, in general_pdf
    textobj.textLine(line)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\reportlab\pdfgen\textobject.py", line 443, in textLine
    self._code.append('%s T*' % self._formatText(text))
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\reportlab\pdfgen\textobject.py", line 410, in _formatText
    for f, t in pdfmetrics.unicode2T1(text,[font]+font.substitutionFonts):
RuntimeError: unexpected exception in unicode2T1 @ src\rl_addons\rl_accel\_rl_accel.c:634
caused by bad argument type for built-in operation
[18/Nov/2022 13:13:25] "GET /general_pdf/2/ HTTP/1.1" 500 73274

Good! Progress is being made.

This is the key line in the traceback:

Given what’s identified later on in the traceback, my initial guess is that you have a character in one of those fields that is causing problems. I’m no expert on reportlab, but you probably need to perform some type of encoding of the data to ensure that reportlab can handle it appropriately.

I’d suggest the first step is to find out which field is causing the issue. There are a couple different ways of doing it, one of the easiest would be log each line before passing it into the textLine method.