Repository navigation
Getting Redirect URL in a GET request #3169
Replies: 1 comment
|
Your HTTPX code already enables HTTP redirects. import httpx
def redirect_urls(client, url):
response = client.get(url, follow_redirects=True)
hops = [(str(hop.url), hop.status_code, hop.headers.get("location"))
for hop in response.history]
return hops, str(response.url)If the final URL is still news.google.com, that response did not send HTTPX to Spiegel with another HTTP redirect. A link in HTML or JavaScript is not an HTTP redirect. Different cookies, request headers, or server-side decisions can also produce different chains. Compare the actual status/Location sequence and final response bodies from both clients; the snippet alone cannot establish which Google behavior caused this difference. Avoid forwarding credentials to unrelated origins while investigating. Validated the helper with a local MockTransport chain containing both relative and absolute redirects, including a final response without a Location. HTTPX redirects. Validation version: HTTPX 0.28.1, Python 3.11.9. |
Uh oh!
There was an error while loading. Please reload this page.
I am struggling with getting redirect url from a GET request with httpx.
Using requests
Output:
I can get the redirect url using requests.
Using httpx
Output:
I cannot get the Redirect URL when using httpx.
Is there anything wrong with my code? Or it is a bug?
All reactions