As shown in the following code:
b64_encoded_bytes = base64.b64encode(zlib.compress(b'abcde'))
encoded_bytes_representation = str(b64_encoded_bytes) # this the cause
zlib.decompress(base64.b64decode(encoded_bytes_representation))
Zlib.decopress error
zlib.error: Error -3 while decompressing: incorrect header check
The reason for this is the use of the str() method
The description of the str() method in the python3 documentation.
If neither encoding nor errors is given, str(object) returns object.str(), which is the “informal” or nicely printable string representation of object. For string objects, this is the string itself. If object does not have a str() method, then str() falls back to returning repr(object).
The str() method only serves to put the
b'eJxLTEpOSQUABcgB8A=='
Converted to
"b'eJxLTEpOSQUABcgB8A=='"
The correct conversion should be to
"eJxLTEpOSQUABcgB8A=="
The solution is to specify the encoding method in the str() method
str(b64_encoded_bytes, 'utf-8')
Read More:
- [Solved] Error “incorrect padding” in decoding of Base64 module in Python
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- Python reads excel and stores it in the list according to the header hash copy.deepcopy
- Python Use sqlalchemy Error: pymssql.ProgrammingError: (102, b“Incorrect syntax near ‘(‘.DB-Lib error
- The automatic token of Python interface is passed into the header
- [Solved] Python Networkx Error: Network error: random_state_index is incorrect
- [Solved] ansible Command Error: Error -5 while decompressing data: incomplete or truncated stream
- [Solved] Saving to Database Error: pymysql.err.DataError: (1366, “Incorrect string value…
- [Solved] Python setup.py install Error: error: identifier “AT_CHECK“ is undefined
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- Python: ___ () vs ___ str__()
- Typeerror in Python regular expression: expected string or bytes like object
- [Solved] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- Django Error: binascii.Error: Incorrect padding [How to Solve]
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Error in installing Python 3.6.8 for MacBook pyenv [Solved]
- Implementation of Kalman Filter in Python
- How to Fix keyerror in Python dictionary lookup
- An introduction to sys modules in Python and how packages are imported and used