There is something very basic that I'm not able to do. In this code :
@app.get('/resume')
async def resume():
path = os.path.abspath(os.getcwd())
with open(f'{path}/cv.pdf', 'rb') as f:
data_binary = f.read()
file_data = base64.b64encode(data_binary)
with open(f'{path}/sample.pdf','wb') as pdf:
pdf.write(file_data)
parsed_data = ResumeParser(pdf).get_extracted_data()
pdf.close()
return await process_pdf(parsed_data)
I'm getting the error TypeError: expected str, bytes or os.PathLike object, not BufferedWriter
over and over again for the line ResumeParser(pdf).get_extracted_data()
when :
parsed_data = ResumeParser(f'{path}/cv.pdf').get_extracted_data()
is working perfectly.
Do you know by any chance what I'm missing here please ?
TYVM.
For the context :
BytesIO
ResumeParser
is coming from this package pyresparser
sample.pdf
file created in my file system.ResumeParser appears to want the path to the file to parse. You are supplying the contents of the file in the pdf variable. you don't need the with clause there. also your with clause would automatically close the pdf file when the with is exited. You do not need the explicit close() call. I have updated that section and included it here.
with open(f'{path}/sample.pdf','wb') as pdf:
pdf.write(file_data)
parsed_data = ResumeParser(f'{path}/sample.pdf').get_extracted_data()
The above code writes and closes the file and then passes the name to resume parser. I think that is what you are trying to do.