Describe the bug
When making a request to a URL with a Fully Qualified Domain Name (FQDN) that includes a trailing dot (e.g., https://pyropus.ca./), requests gets stuck in an infinite redirect loop, eventually raising a requests.exceptions.TooManyRedirects exception.
This happens because the server attempts to redirect the user to the non-FQDN version (without the dot), but requests seems to mishandle the Host header or the redirect state with the trailing dot, causing it to loop infinitely.
To Reproduce
import requests
res = requests.get("https://pyropus.ca./")
Expected behavior
The request should successfully follow the redirect to the non-FQDN URL (https://pyropus.ca/) and return a 200 OK status code, just like web browsers (Chrome/Firefox) or curl do.
Workaround found
If we manually inject the Host header without the trailing dot, it bypasses the loop and returns 200:
custom_headers = {'Host': 'pyropus.ca'}
res = requests.get("https://pyropus.ca./", headers=custom_headers)
print(res.status_code)
System Information
requests version: Latest
- Python version: 3.10+
- OS: Linux
Context
This was discovered while debugging a redirect loop issue inside the Fedora Infrastructure (Anitya project).
Describe the bug
When making a request to a URL with a Fully Qualified Domain Name (FQDN) that includes a trailing dot (e.g.,
https://pyropus.ca./),requestsgets stuck in an infinite redirect loop, eventually raising arequests.exceptions.TooManyRedirectsexception.This happens because the server attempts to redirect the user to the non-FQDN version (without the dot), but
requestsseems to mishandle the Host header or the redirect state with the trailing dot, causing it to loop infinitely.To Reproduce
Expected behavior
The request should successfully follow the redirect to the non-FQDN URL (
https://pyropus.ca/) and return a200 OKstatus code, just like web browsers (Chrome/Firefox) orcurldo.Workaround found
If we manually inject the Host header without the trailing dot, it bypasses the loop and returns
200:System Information
requestsversion: LatestContext
This was discovered while debugging a redirect loop issue inside the Fedora Infrastructure (Anitya project).