I'm currently trying to read through a CSV file that is being provided through Flask-WTF(orms) and I continue to run into issues when trying to load it through csv.DictReader
or pandas
.
The file (a FileStorage
object) is not actually being uploaded anywhere, and I am trying to grab the data within the CSV to use within my code.
This is how I'm trying to grab it now using pandas
f = form.upload.data
data = pandas.read_csv(f.stream)
logger.debug(data)
However this returned the error pandas.errors.EmptyDataError: No columns to parse from file
When I tried grabbing it through csv.reader
this way:
reader = csv.reader(f.read(), delimeter=',')
for row in reader:
logger.debug(row)
I got this error instead: _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
I received a similar error when trying out csv.DictReader
as well.
Has anyone tried to do anything similar to this, or know if this is even possible without uploading the file anywhere? I've looked around but I can't seem to find a proper solution.
For reference, my CSV file has a pretty basic format:
C1,C2
Data,Data
Thanks!