Python Forum
base64 decoding issue or bug
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
base64 decoding issue or bug
#1
hi,

i am encoding data and sending the same through TCP/IP and then trying to decode the same with base64.b64decode() operations, but for some reason i am not able to decode the data when it contains padding as "==", but the same code works when it contains padding as one character "="

But same data when i try with Java decoders it decodes perfectly in both the cases.

Not able to find the issue exactly, getting exception and terminating my simulator

Is it bug in python ?

  File "C:\Python34\lib\base64.py", line 46, in _bytes_from_decode_data
    "string, not %r" % s.__class__.__name__) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'dict' 

Thanks In advance.
Reply
#2
Next time show your code, let us now how you have made it.

So I tried this with python 2 & 3

import base64
encode = base64.b64encode(b"this is a test string asdlka jlkdjasd")
decode = base64.b64decode(encode)

print(encode, end="\n")
print(decode)
Turns out that you have to use b IN PYTHON 3.X, before you write the string that you wish to encode .b64encode(b'blabla')

RESULT (Python 3.x):
Output:
b'dGhpcyBpcyBhIHRlc3Qgc3RyaW5nIGFzZGxrYSBqbGtkamFzZA==' b'this is a test string asdlka jlkdjasd'
RESULT (Python 2.7):
Output:
dGhpcyBpcyBhIHRlc3Qgc3RyaW5nIGFzZGxrYSBqbGtkamFzZA== this is a test string asdlka jlkdjasd
Reply
#3
Read the error message.
You are trying to encode a dictionary object which is not allowed
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decoding lat/long in file name johnmcd 4 270 Mar-22-2024, 11:51 AM
Last Post: johnmcd
  Enigma Decoding Problem krisarmstrong 4 631 Dec-14-2023, 10:42 AM
Last Post: Larz60+
  json decoding error deneme2 10 3,395 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  flask app decoding problem mesbah 0 2,310 Aug-01-2021, 08:32 PM
Last Post: mesbah
  Decoding a serial stream AKGentile1963 7 8,339 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  xml decoding failure(bs4) roughstroke 1 2,211 May-09-2020, 04:37 PM
Last Post: snippsat
  download base64 email attachment cferguson 3 4,647 Feb-25-2020, 06:50 PM
Last Post: cferguson
  python3 decoding problem but python2 OK mesbah 0 1,767 Nov-30-2019, 04:42 PM
Last Post: mesbah
  utf-8 decoding failed every time i try adnanahsan 21 10,588 Aug-27-2019, 04:25 PM
Last Post: adnanahsan
  Base64 to retrieve message JonasH 0 1,624 Jul-22-2019, 04:00 PM
Last Post: JonasH

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020