Hi, I developed an import for csv in admin location, however I obtain the errorFile "D: \ andreas \ Programmierung \ Python \ bestenliste_laufen \ running_results \ ranges \ admin.py", line 30, in import_csvfor row in visitor: _ csv.Error: iterator should return strings, not bytes (did you open up the documents in message setting?)

I adhered to the overview

books.agiliq.com
*

5. Exactly how to import CSV making use of Django admin?-- Django Admin Recipe Book 2.0 ...


admin.pycsv _ documents = request.FILES <"csv_file"> visitor = csv.reader(csv_file)# todo obtain highest possible kind numbersort = 1for row in visitor:

Below is the total code

github.com ad-software/running _ results/blob/master/ running_results/ distances/admin. py

import csvfrom django import formsfrom django.contrib import adminfrom django.shortcuts import redirect, renderfrom django.urls import pathfrom.models import Distancesclass CsvImportForm(forms.Form): csv_file = forms.FileField()course DistancesAdmin(admin.ModelAdmin): list_display = ("https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgsort"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg, "https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgname"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg, "https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgmin"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg, "https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgmax"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg, "https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgcategory"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg) # start csv import change_list_template="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgdistances/distances_changelist.html"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg def get_urls(self): links = incredibly(). get_urls() my_urls =

The issue is that csv.reader anticipates something that returns strings, and also you're obtaining bytes from request.FILES. I located TextIOWrapper in the typical collection (docs right here: https://docs.python.org/3/library/io.html#io.TextIOWrapper) which appears may assist right here:

import iowith io.TextIOWrapper(request.FILES <"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgcsv_file"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg> portions(), encoding="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgutf-8"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg) as text_file: viewers = csv.reader(text_file)You might require to include the delimiter keyword phrase disagreement to csv.reader relying on what the separator is.

Those with even more experience with request.FILES might state I'm incorrect, and also I'm flawlessly great with that said.

Hope this aids!

-Jorge


Hi, I attempted

with io.TextIOWrapper(request.FILES <"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgcsv_file"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg> pieces(), encoding="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgutf-8"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg) as text_file: visitor = csv.reader(text_file, delimiter="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg;"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg)however I obtain the mistake: Submit "D: \ andreas \ Programmierung \ Python \ bestenliste_laufen \ running_results \ ranges \ admin.py", line 33, in import_csvwith io.TextIOWrapper(request.FILES <"csv_file"> pieces(), encoding="utf-8") as text_file: AttributeError: 'generator' item has no quality 'understandable'


I needed to do that lately, below's my strategy:

import csv from io import StringIOcontent = StringIO(uploaded_file. read(). decipher("https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpglatin-1"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg))csv_reader = csv.reader(material, delimiter="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg;"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg)
Thanks for the aid! Currently it is functioning:

with io.TextIOWrapper(request.FILES <"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgcsv_file"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg>, encoding="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpgutf-8"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg, newline="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg\n"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg) as text_file: viewers = csv.reader(text_file, delimiter="https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg;"https://cardonafam.com/iterator-should-return-strings-not-bytes-did-you-open-the-file-in-text-mode/imager_1_7126_700.jpg) for row in visitor: