【问题标题】:Reading and enconding(b64) pdf files in python在python中读取和编码(b64)pdf文件
【发布时间】:2021-01-19 00:39:02
【问题描述】:

我正在尝试以二进制格式打开一个 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")

【问题讨论】:

    标签: python pdf encoding base64


    【解决方案1】:

    您需要使用base64 模块。

    import base64
    
    with open(pod, 'rb') as pdf:
        encoded = base64.b64encode(pdf.read())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 1970-01-01
      • 2014-10-27
      相关资源
      最近更新 更多