Decided: How in Python 3 encode file, for open this file with PHP zlib_decode function?-ThrowExceptions

Exception or error:

EDIT:
I found a fix, must use wb+ option for save binary files and dont use str()

Code in PHP that i cant change:

file_get_contents('data.pak');
$s_st = unserialize(zlib_decode($s_st));

I try this Python code:

import zlib
from phpserialize import serialize

file = zlib.compress(serialize(data), 9)

with open('data.pak', 'w+') as f_out:
    f_out.write(str(file))
    f_out.close()

But PHP cant open this file.
I also install PHP to check what file create zlib_encode (zlib_encode(serialize($data),15)) with same data, and these files are different.

Python file starts from:

b’\xa5\xbd\xcb\xb2,)\xaeh\xdb\x8e\xf3\x19\xd5O3\xe7\rY_s\x9b\xbb\xbd\x9b\xd7\xce\xbf\

Looks like file content in bytes

PHP file starts from:

њҐќ[Ом(і¦ЇіҐћDЯ—dО°{X=©‰ њ пЗRХ_»цЄ§Н1€гяыw]!‡ящ?ЖеЏsсъ„l?—фЧяю_ќuз!Фz¤СЙ`\ши

So my question is: How create file in Python, that I can then open in PHP, using code at the beginning.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *