How to resolve “iterator should return strings, not bytes”

后端 未结 3 1233
悲&欢浪女
悲&欢浪女 2021-02-03 20:44

I am trying to import a CSV file, using a form to upload the file from the client system. After I have the file, I\'ll take parts of it and populate a model in my app. However,

3条回答
  •  我在风中等你
    2021-02-03 21:02

    Fuse your two methods, this never fails in Python 3.5.2 and Django 1.9

    delimitador = list_delimitadores[int(request.POST['delimitador'])][1]
    try:
        text = TextIOWrapper(request.FILES['csv_x'].file, encoding='utf-8 ', errors='replace')
        reader = csv.reader(text, delimiter=delimitador)
    except:
        text = StringIO(request.FILES['csv_x'].file.read().decode())
        reader = csv.reader(text, delimiter=delimitador)
    

提交回复
热议问题