How Can I Handle The Error "expected Str, Bytes Or Os.PathLike Object, Not InMemoryUploadedFile' In Python Or Django?
Before explaining my problem in detail, here are my codes. models.py class SimilarStore(models.Model): store = models.ForeignKey(Store) domain = models.CharField(max_lengt
Solution 1:
csv_file
is already a file; you don't need to open it. Just pass it straight to csv.reader()
.
reader = csv.reader(csv_file)
Solution 2:
When the file to read is already open, we have a problem, because of the fact that by removing the open line, we will obtain the following error.
iterator should return strings, not bytes (did you open the file in text mode?)
I had the same error, and, to avoid it, I made(CSVfile is my CSV file which is already open):
decoded_file = CSVfile.read().decode('utf-8').splitlines()
reader = csv.reader(decoded_file, delimiter=delimitation)
Then, with that, I can pass into my CSVfile csv file by the loop:
for row in reader:
Post a Comment for "How Can I Handle The Error "expected Str, Bytes Or Os.PathLike Object, Not InMemoryUploadedFile' In Python Or Django?"