I want to decompress the following gz compressed string using python3.6:
H4sIAAAAAAAA//NIzcnJVwjPL8pJAQBWsRdKCwAAAA==
The decompressed string is "Hello World"
I was able to decompress it using online tool - http://www.txtwizard.net/compression but I couldn't find a proper way to do it in python.
I tried zlib and gzip, but they require bytes not str. I also tried converting it using io.Bytes() but of no use. My Code is:
import gzip
import io
class SearchEvents:
def decompressPayload():
payload = "H4sIAAAAAAAA//NIzcnJVwjPL8pJAQBWsRdKCwAAAA=="
payload_bytes = io.BytesIO(payload)
print(gzip.decompress(payload_bytes))
SearchEvents.decompressPayload()
I am expecting "Hello World" as output. But I am getting the following error:
Traceback (most recent call last):
File "SearchEvents.py", line 13, in <module>
SearchEvents.decompressPayload()
File "SearchEvents.py", line 10, in decompressPayload
payload_bytes = io.BytesIO(payload)
TypeError: a bytes-like object is required, not 'str'
Is there any way to achieve what I want?
I want to decompress the following gz compressed string using python3.6:
...==
That's not a gzip-compressed string. At least, not until you Base64-decode it first.
>>> gzip.decompress(base64.b64decode('H4sIAAAAAAAA//NIzcnJVwjPL8pJAQBWsRdKCwAAAA=='))
b'Hello World'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With