Python Base64编码结果与在线工具

时间:2017-12-11 04:21:29

标签: python python-2.7 encoding base64

我正在尝试编码pdf文档。编码文档通过API发送以生成响应。我使用了两种编码文档的方法:第一种是使用在线工具https://www.base64encode.org/,第二种是使用python库base64。但是我得到了同一文档的两个不同结果,而在线工具生成的结果是正确的,因为我从API获得了成功的响应。 在线工具的结果:

  

QW1pdGF2YSBHaG9zaA0KU1ZQICYgSGVhZCAtIE5vcnRoIEFzaWEgLSBKYXBhbiwgQ2hpbmEsIEtvcmVhLCBISyBhbmQgVGFpd2FuKSBhdCBUZWNoIE1haGluZHJhDQphbWl0YXZhZ2hvc2gxMkB5YWhvby5jby5pbg0KU3VtbWFyeQ0KQ3VycmVudCANClNWUCAmIEJ1c2luZXNzIEhlYWQtIEphcGFuLCBHcmVhdGVyIENoaW5hICYgS29yZWEgICAgIFRlY2ggTWFoaW5kcmEgTHRkDQpBbWl0YXZhIGhhcyBqb2luZWQgVGVjaCBNYWhpbmRyYSBpbiAyMDA3LiBBbWl0YXZhIGhhcyBiZWVuIHdpdGggVGVjaCBNYWhpbmRyYSBmb3IgdGhlIGxhc3QgOSB5ZWFycyBhbmQgaGFzIHBlcmZvcm1lZCBsZWF​​kZXJzaGlwIHJvbGVzIGluIHZhcmlvdXMgY2FwYWNpdGllcyBmb3IgbXVsdGlwbGUgZ2VvZ3JhcGhpZXMgYW5kIGRvbWFpbnMuDQpIZSBpcyB0aGUgSGVhZCBvZiBCdXNpbmVzcyBmb3IgSmFwYW4sIEdyZWF0ZXIgQ2hpbmEgYW5kIEtvcmVhIE9wZXJhdGlvbnMgZm9yIFRlY2ggTWFoaW5kcmEgKHd3dy50ZWNobWFoaW5kcmEuY29tKS4gQW1pdGF2YSBpcyBhbHNvIHRoZSBSZXByZXNlbnRhdGl2ZSBEaXJlY3RvciBmb3IgSmFwYW4gT3BlcmF0aW9ucyBvZiB0aGUgQ29tcGFueSBhbmQgdGhlIFdob2xlIHRpbWUgRGlyZWN0b3IgYXQgdGhlIEJv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hZ2VtZW50LCAxOTg2IC0gM Tk4OCBBY3Rpdml0aWVzIGFuZCBTb2NpZXRpZXM6IENTSSBEZWxoaSBVbml2ZXJzaXR5IFBoeXNpY2FsIFNjaWVuY2VzLCAxOTgyIC0gMTk4NSBEZSBOb2JpbGkgMTk3MCAtIDE5ODA =

Python代码:

import base64

from base64 import b64encode

file="file.pdf"
def bas64(file):
    path="Path to parent folder\\"
    with open(path+file) as f:
        encoded = base64.b64encode(f.read())
    return encoded

output=bas64(file1) 

结果:

  

JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEuMSkKL1Byb2R1Y2VyIChBcGFjaGUgRk9QIFZlcnNpb24gMS4xKQovQ3JlYXRpb25EYXRlIChEOjIwMTcwOTA3MTQ1NDUxWikKPj4KZW5kb2JqCjUgMCBvYmoKPDwKICAvTiAzCiAgL0xlbmd0aCAxMSAwIFIKICAvRmlsdGVyIC9GbGF0ZURlY29kZQo + PgpzdHJlYW0KeJydlndYU + cex99zTvZgJCFsCHuGpUAAkRGmgAzZohCSAAESICQM90BUsKKoyFIEKYpYsFqG1IkoDori3g1SBJRarOLC0USep / X29t7b2 + 8f53ye3 / v7vef9jfd5DgCkgEyuMBdWAUAokogj / L0ZsXHxDOwAgAEeYIA9ABxubrZXWFgwkCvQl83IlTuBf9GrmwBSvK8xFXuB / 0 + q3GyxBAAoTM6zePxcrpyL5JyZL8lW2CflTEvOUDCMUrBYfkA5ayg4dYatP / vMsKeCeUIRT86Rcs7mCXkK7pXzhjwpX86IIpfiPAE / X87X5WycKRUK5PxGESvkc + Q5oEgKu4TPTZOznZxJ4sgItpznAIAjpX7ByV + whF8gUSTFzsouFAtS0yQMc64Fw97FhcUI4Odn8iUSZhiHm8ER8xjsLGE2R1QIwEzOn0VR1JYhL7KTvYuTE9PBxv6LQv3Xxb8pRW9n6EX4555B9P4 / BH / ll9UAAGtKXpstf9iSqwDoXAeAxt0 / bMZ7AFCW963j8hf50BXzkiaRZLva2ubn59sI + FwbRUF / 1/90 + Bv64ns2iu1 + LW /迪拉姆/ CkWZKGIq6cbMys6RiRm42h8tnMP88xP848K / PYR3BT + GL + SJ5RLR8ygSiVHm7RTyBRJAlYghE / 6mJ / zDsT5qZa7mojR8BLdEGqFymAeTnfoCiEgGSsFu + Av3et2B8NFDcvBj90Zm5 / yzo3 3eFyxSPXEHq5zh2RCSDKxXnzawpriVAAwJQBjSgCfSAETAHTOAAnIEb8AS + YB4IBZEgDiwGXJAGhEAM8sEysA ==

对导致问题的原因有什么想法?

0 个答案:

没有答案