Created
November 20, 2019 15:58
-
-
Save splashx/b5c646210d9b2ddc51541c2cc420efdb to your computer and use it in GitHub Desktop.
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
# Run squid | |
# docker run --name squid -d --restart=always \ | |
# --publish 3128:3128 \ | |
# sameersbn/squid:3.5.27-2 | |
import requests | |
# from urllib3.contrib import pyopenssl | |
# pyopenssl.extract_from_urllib3() | |
CHUNKSIZE = 1024 * 64 # 64kB | |
def _chunk_body(body): | |
chunk = body | |
while chunk: | |
chunk = body.read(CHUNKSIZE) | |
if not chunk: | |
break | |
yield chunk | |
s = requests.Session() | |
proxies = { | |
"http": "http://localhost:3128", | |
"https": "http://localhost:3128", | |
} | |
# test file should be created, any file will do | |
# e.g.: dd if=/dev/zero of=file.txt count=1024 bs=1024 | |
data = open("file.txt", 'rb') | |
headers = { 'Accept-Encoding': 'gzip, deflate', | |
'Accept': '*/*', | |
'Connection': 'application/octet-stream'} | |
resp = s.request("PUT","https://jsonplaceholder.typicode.com/posts/1", | |
headers=headers, | |
data=_chunk_body(data), | |
proxies=proxies, | |
timeout=10,) | |
print(resp.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment