import requests, uuid
GATE = "gate.aeonproxy.com:7000"
# Country key only. GeoLite files half of one TIM San Marino block under Coriano, Italy,
# and prints Borgo Maggiore for most of the rest: trust the country field, not the town.
NETWORK = {"AS15433": "TIM San Marino", "AS196874": "Telenet", "AS212841": "AASS"}
def sammarinese_exit(attempts=6):
for _ in range(attempts):
login = f"ap_a1b2c3-cc-sm-sid-{uuid.uuid4().hex[:8]}-time-1800"
proxy = f"http://{login}:PASS@{GATE}"
try:
seen = requests.get("https://ipinfo.io/json", proxies={"http": proxy, "https": proxy}, timeout=15).json()
except requests.RequestException:
continue # no reply: try a new session
if seen.get("country") == "SM":
seen["network"] = NETWORK.get(seen.get("org", "").split(" ")[0], seen.get("org"))
return proxy, seen # the same address for 30 minutes
return None, None # none free right now: try again later
proxy, seen = sammarinese_exit()
if proxy:
print(seen["ip"], seen["network"], seen.get("city"))
page = requests.get("https://www.titancoop.sm/promozioni", headers={"Accept-Language": "it-IT,it;q=0.9"},
proxies={"http": proxy, "https": proxy}, timeout=20)
print(page.status_code, len(page.text))
The function returns nothing when no address answers, which can happen with 61 addresses, so call it again a little later. Any length from 60 to 21600 seconds works in -time-; a login with no -sid- rotates per request.