Skip to content

TooManyRedirects exception loop when requesting FQDN URLs with a trailing dot #7209

Description

@YatesMold

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).

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions