Skip to content

Instantly share code, notes, and snippets.

@AntonSmolkov
Last active May 7, 2021 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntonSmolkov/110fe7ae6b3ed337842a5be1a79db0c8 to your computer and use it in GitHub Desktop.
Save AntonSmolkov/110fe7ae6b3ed337842a5be1a79db0c8 to your computer and use it in GitHub Desktop.
Sample python gzip http post
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