将文档动态编码/解码到base64

时间:2015-09-25 22:57:30

标签: python shell

如何将文件夹中的pdf和word文件编码为base64并对其进行解码并保存到同一文件夹中? pdf和word文件是通过Web服务动态生成的。

我想用python来做这件事。

我用过这个。但它给出了错误 回溯(最近一次调用最后一次):

文件“sample.py”,第7行,in     base64.encode(open(“hello.pdf”),open(“hello1.b64”,“w”))   文件“C:\ Python34 \ lib \ base64.py”,第496行,编码     s = input.read(MAXBINSIZE)   在解码中文件“C:\ Python34 \ lib \ encodings \ cp1252.py”,第23行     return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError:'charmap'编解码器无法解码位置1340中的字节0x9d:字符映射

base64.encode(open("hello.pdf"), open("hello1.b64", "w"))

1 个答案:

答案 0 :(得分:1)

base64模块,它包含在标准库中。文档为here

相关问题