2

I'm sending a base64 string compressed with zlib in Python, converted to base64, sent to a PHP page where it will be extracted.

I'm having trouble with this. How would I do this?

Right now I have:

python

compressor = zlib.compressobj(wbits=(16+zlib.MAX_WBITS))
compressed = compressor.compress(str)
compressed += compressor.flush()

php

*POST deccoded here, b64data is the output*
$b64data = zlib_decode($data);

I left out the part where I decode from base64. The php code throws and error about invalid data at the zlib function. zlib_decode(): data error

6
  • um. ... base64_decode($b64data) maybe... base64_decode , just guessing. Commented Mar 3, 2019 at 1:34
  • Yeah I left that part out. I'm not having trouble decoding. It throws an error about invalid compression at the zlib function. Commented Mar 3, 2019 at 1:35
  • Your code doesn't contain the base64 de-/coding. Maybe try this first with an uncompressed string to drill down the cause of problem. Commented Mar 3, 2019 at 1:35
  • 1
    It throws an error about invalid compression at the zlib function that would have been nice to know, you may want to add that to the question. Commented Mar 3, 2019 at 1:36
  • Using wbits=(16+zlib.MAX_WBITS) creates a gzip-header instead of the zlib header for wbits=zlib.MAX_WBITS. I don't know if PHP can cope with that. Commented Mar 3, 2019 at 1:41

1 Answer 1

1

Ok, I messed up and the problem wasn't with the zlib function.

Long story short I used to encode the data twice on the Python side but changed it to only encode once and never removed the extra base64_decode from the PHP.

Thanks for the help guys.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.