New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue from python in encode base64 with Json Model #69262
Comments
Hi, issue from python in encode base64 with Json Model in twice encode with base64 output python different with JAVA and C# , if programmer using rest-service in server side and other programmer using UI(Python Django) in client site , this encode different for encode and decode with match json encode model, real example : 1- go to https://www.base64encode.org/ now second output python json model : Microsoft Windows [Version 6.2.9200] C:\Users\Matthew F4rr3ll>python
Python 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> s1='{"userName":"admin","password":"admin"}'
>>> s2 = s1.encode("base64")
>>> e = s2.encode("base64")
>>> print e
ZXlKMWMyVnlUbUZ0WlNJNkltRmtiV2x1SWl3aWNHRnpjM2R2Y21RaU9pSmhaRzFwYmlKOQo=
now check this output : you see in two encode different in end line in ("o=" != "==") also i know resolve this but you should fix in end line encode match with other language Thanks, |
This seems to be as documented. Have a look at the definition of “base64_codec” under <https://docs.python.org/2/library/codecs.html#python-specific-encodings\>, which says “the result always includes a trailing '\n' ”. In fact, line breaks are also added for longer encodings so that each line is ≤ 76 symbols. >>> e.decode("base64")
'eyJ1c2VyTmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJhZG1pbiJ9\n' Your alternative encoding does not include that trailing newline. If you don’t want the “MIME Base-64” multiline encoding maybe you should use something like base64.b64encode() directly. See also bpo-16473 where I proposed a patch to fix the Python 3 documentation that links to the wrong equivalent function. |
why any update in python 2.7? you should using a function this code change : enc_sec = ZXlKMWMyVnlUbUZ0WlNJNkltRmtiV2x1SWl3aWNHRnpjM2R2Y21RaU9pSmhaRzFwYmlKOQo=
url = re.sub('\o=$','',enc_sec)
result = url.replace('\n','==')
print result |
no close plz, i using python 2.7.3 i get this output without "\n"? code: Output: eyJ1c2VyTmFtZSI6ICJhZG1pbiIsICJwYXNzd29yZCI6ICJhZG1pbiJ9 ZXlKMWMyVnlUbUZ0WlNJNklDSmhaRzFwYmlJc0lDSndZWE56ZDI5eVpDSTZJQ0poWkcxcGJpSjk= |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: