You can try encoding the PDF content in base64 before attaching it.
import base64
# Encode the PDF content in base64
pdf_content_base64 = base64.b64encode(pdf_content).decode('utf-8')
# Attach PDF
email.attach(filename, base64.b64decode(pdf_content_base64), 'application/pdf')