G
G
GrYeOl2020-08-28 12:26:07
PHP
GrYeOl, 2020-08-28 12:26:07

Pass gzip from PHP to Python?

You need to pass a compressed JSON string from the PHP server to the Python server.

I'm trying to do so

$json_out = "{"1":{"a1":3,"a2":0,"c":1,"d":1,"e":1},"2":{"a1":3,"a2":2,"c":3,"d":3,"e":1},"3":{"a1":3,"a2":2,"c":3,"d":1,"e":2}}";
$gz_data = gzcompress($json_out, 9, ZLIB_ENCODING_GZIP);
...
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(['json_out'=>$gz_data]));

and
gz_data = req.POST.get('json_out', 'undef')
json_in = gzip.decompress(gz_data)

I get an error: a bytes-like object is required, not 'str'
If I do this
gz_data_bytes = bytes(gz_data, 'utf-8')
json_in = gzip.decompress(gz_data_bytes )

Then: Not a gzipped file (b'\x1f\xef')

What's wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question