在 python 中读取和编码 (b64) pdf 文件
Reading and enconding(b64) pdf files in python
我正在尝试以二进制格式打开 pdf 文件并将其编码为 base64("utf-8"),但我收到了这条错误消息:
AttributeError: '_io.BufferedReader' 对象没有属性 'b64encode'
我在 windows 10 和 python 3 工作,代码:
attach_file_name = os.getcwd() + '\doc.pdf'
attach_file = open(attach_file_name, "rb")
attach_file = attach_file.b64encode("utf-8")
您需要使用 base64
模块。
import base64
with open(pod, 'rb') as pdf:
encoded = base64.b64encode(pdf.read())
我正在尝试以二进制格式打开 pdf 文件并将其编码为 base64("utf-8"),但我收到了这条错误消息:
AttributeError: '_io.BufferedReader' 对象没有属性 'b64encode'
我在 windows 10 和 python 3 工作,代码:
attach_file_name = os.getcwd() + '\doc.pdf'
attach_file = open(attach_file_name, "rb")
attach_file = attach_file.b64encode("utf-8")
您需要使用 base64
模块。
import base64
with open(pod, 'rb') as pdf:
encoded = base64.b64encode(pdf.read())