I am getting the excel file in the request body, but when I try to read through openpyxl
or xlrd
, it is raising the error.
The FastAPI endpoint:
def upload_file(request: Request, file: UploadFile = File(...), db: Session = Depends(get_db)):
for part in decoder.MultipartDecoder(request.get("body").encode('utf-8'), request.get("headers").get("Content-Type")).parts:
content = part.text
file_open = pd.read_excel(content.encode('utf-8'), engine='xlrd')
pc_sheet_names = file_open.sheet_names
The error:
File "/var/lang/lib/python3.9/zipfile.py", line 1361, in _RealGetContents
raise BadZipFile("Bad magic number for central directory")