Search code examples
pythonbase64decode

python base64.b64decode(): Is there any limit to length of input (encoded) string


I am using python base64.b64decode() to decode some string fetched from google using REST API. I am able to decode small chunks but not whole encoded string. I tried string upto 4k length to decode, but full string (of length 21k) is not able to decode.

Is there any limit on length of input to base64.b64decode().

example code

import base64
encoded_buffer = "ICAgICAgICAgIC<omitting long string (21k long) fetched from google>"
decoded_buffer = base64.b64decode(encoded_buffer)

Solution

  • Yes, the limit depends on the buffer size. If the buffer size is not big enough you will get an error

    SyntaxError: EOL while scanning string literal

    In that case try to increase the buffer size

    sock.recv(buffer size) # default 1024