1

I'm trying to open a pdf file in binary and encode it in base64("utf-8"), but I'm getting this ERROR message:

AttributeError: '_io.BufferedReader' object has no attribute 'b64encode'

I'm working in windows 10 and python 3, code:

attach_file_name = os.getcwd() + '\doc.pdf'
attach_file = open(attach_file_name, "rb")
attach_file = attach_file.b64encode("utf-8")

1 Answer 1

1

You need to use the base64 module.

import base64

with open(pod, 'rb') as pdf:
    encoded = base64.b64encode(pdf.read())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.