I have to pass one value in payload for REST API as dynamic value which need to be converted to Text to Gzip Compress using Python2.7

Viewed 10

In payload one value is as below to be converted this value to Gzip Compress in Python for REST API as we are using Python 2.7

Original Value:-

<ATTACHMENT_ID>ff38fac4-d962-49b1-843f-34d352b6ff49</ATTACHMENT_ID>0cc5e563-42e5-4e37-81ce-f25cc8756346<SF_OBJECT_ID>7d80f6ad-803b-475c-86b7-f10e28986df7</SF_OBJECT_ID><SF_OBJECT_TYPE>Agreement</SF_OBJECT_TYPE><SF_OBJECT_VERSION>1.0</SF_OBJECT_VERSION><SF_TEMPLATE_VERSION></SF_TEMPLATE_VERSION><SF_BUSINESS_OBJECT_CONTEXT>Agreement</SF_BUSINESS_OBJECT_CONTEXT>FalseFalse

To be converted to gzip compress

H4sIAAAAAAAACn2Sb2+CMBDGP1HHvwIlaUgQ62SZaEZntlcG2qsjEUoAZ/btByZOdNne3T33e55ek6NR08+12LS6gbYvoQtpxHkUL1cs5btkHirlEJULjGTg2QgHhYUIdhRysHRcu/CUwgE1bj10SDxWUPdDbQrhgus5CNvgIgyOj4glACnbFYL4wwR71JgY6AraPSS10iHdQtuVug6pca0m42yxW8+eWHx+1JfEVF4uETGdAmHfFYh4hY+UZYJNAuJJ5VPjxjIJ4O8bFkb7FmBcY8qdJxNyy16yZJ2G1oM5xS7ySHK22jxHnF3FEfytDuLsNUtSlmWXmHidcvbG71b5i6IcquaQ9zB+xpg2y7zLqrztkx6qcJEfOqDGjUZf4LOE02Orj00iB/ddvywlZB/6dHbEuu6HXWb6WMu8/foJ/I8ZjuL+tL4Bxmc3aG0CAAA=

I am able to do this using this link online - https://www.multiutil.com/text-to-gzip-compress/

I explored many options in python2.7 but was not able to get the exact format after encoding as mentioned above. I need the exact string as above after encoding.

I tried using the below code, but it is not giving me the required value after encoding

code = base64.b64encode(zlib.compress(compress, 9)) code = code.decode('utf-8')

1 Answers

The "original value" you provided does not match the decompression of the gzip data you provided. The latter is:

<AptDocProperties><ATTACHMENT_ID>ff38fac4-d962-49b1-843f-34d352b6ff49</ATTACHMENT_ID><DocumentID>0cc5e563-42e5-4e37-81ce-f25cc8756346</DocumentID><MergeInfo><Version></Version></MergeInfo><SF_OBJECT_ID>7d80f6ad-803b-475c-86b7-f10e28986df7</SF_OBJECT_ID><SF_OBJECT_TYPE>Agreement</SF_OBJECT_TYPE><SF_OBJECT_VERSION>1.0</SF_OBJECT_VERSION><SF_TEMPLATE_VERSION></SF_TEMPLATE_VERSION><SF_BUSINESS_OBJECT_CONTEXT>Agreement</SF_BUSINESS_OBJECT_CONTEXT><TemplateID></TemplateID><HasSmartItem>False</HasSmartItem><ReviewGroupId></ReviewGroupId><HideShowSmartContentBoundary>False</HideShowSmartContentBoundary></AptDocProperties>

There some similar substrings, but otherwise entirely different.

So maybe you should start by figuring out why that is.

Even once you get your data to match your data, you should not expect to be able to reconstruct the exact same compressed gzip stream. All that matters, and all you need to do, it make a gzip stream that decompresses to exactly what you started with.

Related