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, 2023 in Others by Kithuzzz
• 38,010 points
949 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, 2023 by narikkadan
• 63,420 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
• 63,420 points
1,773 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, 2023 in Others by narikkadan
• 63,420 points
339 views
0 votes
1 answer

Find specific term in a text string and return that term in the previous column

Try: You can either hard code the ...READ MORE

answered Apr 10, 2023 in Others by Kithuzzz
• 38,010 points
297 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,921 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, 2023 in Others by Kithuzzz
• 38,010 points
753 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,604 views
0 votes
1 answer
0 votes
1 answer

Can an Excel xll function indicate that the return value should be displayed as a date and not a number?

To my knowledge, the only method to ...READ MORE

answered Jan 5, 2023 in Others by narikkadan
• 63,420 points
515 views
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
• 63,420 points
987 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