Skip to content

Examples

from lupaxa.real_url import resolve

landing = resolve("https://example.com")
print(landing)
real-url https://example.com

Inspect the whole chain

from lupaxa.real_url import resolve

for url in resolve("https://example.com", full=True):
    print(url)
real-url --full https://example.com

Include status codes

from lupaxa.real_url import resolve

for hop in resolve("https://example.com", status=True):
    print(f"{hop.status} {hop.url}")
real-url --status https://example.com

Detect a loop

from lupaxa.real_url import RedirectLoopError, resolve

try:
    resolve("https://example.com")
except RedirectLoopError as exc:
    print("Loop:", [hop.url for hop in exc.hops])

Cap the hop count

from lupaxa.real_url import TooManyRedirectsError, resolve

try:
    resolve("https://example.com", max_redirects=5)
except TooManyRedirectsError as exc:
    print(f"Stopped after {len(exc.hops)} hops")

Shell

Capture the landing URL when the lookup succeeds:

if landing="$(real-url https://example.com)"; then
    echo "Landed on $landing"
else
    echo "Could not resolve"
fi

Print the chain with statuses:

real-url --status https://example.com