Last active
May 7, 2021 09:46
-
-
Save AntonSmolkov/110fe7ae6b3ed337842a5be1a79db0c8 to your computer and use it in GitHub Desktop.
Sample python gzip http post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
import gzip | |
import requests | |
def zip_payload(payload: str) -> bytes: | |
btsio = BytesIO() | |
g = gzip.GzipFile(fileobj=btsio, mode='w') | |
g.write(bytes(payload, 'utf8')) | |
g.close() | |
return btsio.getvalue() | |
headers = { | |
'Content-Encoding': 'gzip' | |
} | |
payload = '{"mydummy": "json"}' | |
zipped_payload = zip_payload(payload) | |
requests.post("http://localhost:8041", zipped_payload, headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment