Iterator should return strings not bytes the file should be opened in text mode

0 votes

My code.

def import_excel(request):

  if request.method == 'POST':
    person_resource = PersonResource()

    dataset  = Dataset()
    new_person = request.FILES['myfile']
    if not new_person.name.endswith('csv'):
      messages.info(request,'Wrong format')
      return render(request,'upload.html')
    
    imported_data = dataset.load(new_person.read(),format='csv')
    for data in imported_data:
      value = Person(
        data[0],
        data[1],
        data[2]
      )
     value.save()
  return render(request,'upload.html')

While importing the CSV file to the database getting the error like this:

iterator should return strings, not bytes (the file should be opened in text mode)

Jan 21 in Others by Kithuzzz
• 34,760 points
124 views

1 answer to this question.

0 votes

You can read the data of the uploaded file as follows and the problem will be solved.

new_person = request.FILES['myfile'].read().decode("utf-8")
answered Jan 21 by narikkadan
• 60,280 points

Related Questions In Others

0 votes
1 answer

Text with a dash in the cell but not in the formula bar (Excel)

What you have got here is called ...READ MORE

answered Nov 13, 2022 in Others by narikkadan
• 60,280 points
247 views
0 votes
1 answer

How do I run a VBA Sub routine continuously when working in a Workbook and not only when the Workbook is opened?

on Thisworkbook, put: Private Sub Workbook_Open() Call checkPW(True) End Sub Then ...READ MORE

answered Jan 14 in Others by narikkadan
• 60,280 points
85 views
0 votes
1 answer

What are the file permissions in Linux?

There are 3 types of permissions in ...READ MORE

answered Mar 8, 2019 in Others by Naba
1,177 views
0 votes
1 answer

Change the permission for a file created by me in linux

If you are the system administrator or ...READ MORE

answered Mar 8, 2019 in Others by Nabarupa
465 views
0 votes
1 answer

Django upload and process multiple files failing with libreoffice

The problem happens when LibreOffice tries to ...READ MORE

answered Feb 20 in Others by Kithuzzz
• 34,760 points
88 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
1,202 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Excel formula for searching two text in one cell and return values based on the result

You can include a second IF within ...READ MORE

answered Oct 10, 2022 in Others by narikkadan
• 60,280 points
348 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP