-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests_http.py
More file actions
34 lines (25 loc) · 966 Bytes
/
requests_http.py
File metadata and controls
34 lines (25 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Load requests from an encrypted paker bundle and make HTTP calls.
Requires requests installed for the dump step: pip install requests
"""
import json
import os
import sys
import paker
KEY = os.urandom(32)
print("Dumping requests (encrypted)...")
bundle = paker.dumps("requests", key=KEY)
blob = json.dumps(bundle)
print(f"Bundle: {len(blob):,} bytes")
print(f"Source readable: {'def ' in blob[:1000]}\n")
for name in list(sys.modules):
if name.startswith("requests"):
del sys.modules[name]
with paker.loads(blob, key=KEY) as imp:
import requests
print(f"requests {requests.__version__} loaded from paker\n")
r = requests.get("https://httpbin.org/get", params={"source": "paker"})
print(f"GET https://httpbin.org/get")
print(f" Status: {r.status_code}")
print(f" Origin: {r.json().get('origin', 'unknown')}")
r = requests.get("https://httpbin.org/user-agent")
print(f"\nUser-Agent: {r.json()['user-agent']}")