Я пытаюсь загрузить файл CSV в Elasticsearch в Django, используя следующий код:
uploadfile.html
<body>
<form action="indexfile" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<input type="submit">
</form>
</body>
, где indexfile - это путь в файле urls.py
from django.urls import path
from . import views
urlpatterns = [
path('indexfile', views.indexfile)
]
views.py
def indexfile(request):
from elasticsearch import Elasticsearch, helpers
import csv
es = Elasticsearch(<endpoints>)
es.indices.create(index='demo', ignore=400)
reader = csv.DictReader(request.FILES['myfile'])
helpers.bulk(es, reader, index="demo", doc_type='mytype')
return render(request, 'add/result.html')
но, это дает мне следующую ошибку
Error at /indexfile
iterator should return strings, not bytes (did you open the file in text mode?)
Как я могу решить эту ошибку?