在我的过程中,我需要将文件上传为django:
newFile = request.FILES['file']
然后在另一个大功能中,我用熊猫打开它:
data = pandas.read_csv(data_file, engine = 'python', header=headers_row, encoding = 'utf-8-sig')
然后我需要上传
uploaded_file = Uploaded_file(file = newFile, retailer = ret, date = date)
但是随机地(例如50/50)我得到了ValueError:关闭文件上的I / O操作。
有什么解决办法吗?是否可以再次打开该文件,或者可以复制该文件并在其中一个使用熊猫并上传另一个?
我稍后尝试过,但是我不确定走这条路线的含义:
from io import BytesIO
output = BytesIO(newFile.file.read())
目前可以使用,但对此我将不胜感激