Skip to content

Instantly share code, notes, and snippets.

@danifus
danifus / requests_strict_raise_for_error.py
Last active July 22, 2021 01:19
Content-Length checking for requests 2
"""Raise an error if the 'Content-Length' header does not match sent bytes.
Requests 2 doesn't raise an error if the value in the 'Content-Length' header
doesn't match the number of bytes actually received. This has been addressed in
requests 3 but the following is handy in the meantime.
https://github.com/psf/requests/pull/3563
https://github.com/psf/requests/issues/4956
"""
from requests.exceptions import HTTPError
@danifus
danifus / create_aes_zip.py
Created July 27, 2019 03:18
Implementing Winzip AES encryption / decryption with zipfile refactor
import zipfile
import zipfile_aes
secret_password = b'lost art of keeping a secret'
with zipfile_aes.AESZipFile('new_test.zip',
'w',
compression=zipfile.ZIP_LZMA,
encryption=zipfile_aes.WZ_AES) as zf:
zf.setpassword(secret_password)