Download scripts/check_proxy_hops.py from Gaurav711/HyperFlow: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/Gaurav711/HyperFlow/resolve/main/scripts/check_proxy_hops.py
- Command line
-
hf download hf://spaces/Gaurav711/HyperFlow/scripts/check_proxy_hops.py
-
curl -L -o check_proxy_hops.py https://huggingface.co/spaces/Gaurav711/HyperFlow/resolve/main/scripts/check_proxy_hops.py
1.65 kB
| """Check that the live login rate limit is per client behind the platform proxy. | |
| One machine exhausts its per-address login limit; a second machine with a different public address | |
| then makes one attempt inside the same 60-second window. A 401 for the second machine means clients | |
| are told apart correctly; a 429 means every caller shares one bucket (wrong proxy hop count). | |
| Usernames are random and never exist, so no account is locked or touched. | |
| """ | |
| import argparse | |
| import json | |
| import secrets | |
| import sys | |
| import time | |
| import httpx | |
| def attempt(client, base): | |
| return client.post(base + '/api/v2/auth/login', json={'username': 'probe-' + secrets.token_hex(8), | |
| 'password': 'not-a-real-password-' + secrets.token_hex(4)}).status_code | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--base', default='https://gaurav711-hyperflow.hf.space') | |
| parser.add_argument('--mode', choices=['exhaust', 'probe'], required=True) | |
| parser.add_argument('--at', type=float, help='probe: unix time to send the single attempt') | |
| args = parser.parse_args() | |
| with httpx.Client(timeout=30) as client: | |
| if args.mode == 'exhaust': | |
| statuses = [attempt(client, args.base) for _ in range(13)] | |
| result = {'mode': 'exhaust', 'statuses': statuses, 'limited': statuses[-1] == 429, 'at': time.time()} | |
| else: | |
| time.sleep(max(0, args.at - time.time())) | |
| result = {'mode': 'probe', 'status': attempt(client, args.base), 'at': time.time()} | |
| print(json.dumps(result)) | |
| sys.exit(0) | |
| if __name__ == '__main__': | |
| main() | |