Skip to content

_get_paged drops context path when resolving next-page URL on Server deployments #1668

Description

@dansailer

When Confluence is deployed under a context path (e.g. https://host/confluence), _get_paged silently constructs a wrong URL for every page after the first, causing the request to hit https://host/rest/api/... instead of https://host/confluence/rest/api/....

Affected version: 5.0.3 (Server/v1 endpoint via ConfluenceBase._get_paged)

Reproduction

Point the client at a Confluence Server instance with a context path:

from atlassian import Confluence
c = Confluence(url="https://host/confluence", username="u", password="p")
list(c.get_page_child_by_type("PAGE_ID_WITH_MORE_THAN_25_CHILDREN"))

The first request goes to https://host/confluence/rest/api/content/{id}/child/page?limit=25&start=0 and succeeds. Confluence returns:

"_links": { "next": "/rest/api/content/{id}/child/page?limit=25&start=25" }

_get_paged then resolves the next URL via:

parsed = urlparse(self.url)                        # https://host/confluence
site_url = f"{parsed.scheme}://{parsed.netloc}"    # https://host  ← drops /confluence
url = f"{site_url}/{next_link.lstrip('/')}"        # https://host/rest/api/...

The second request hits https://host/rest/api/... (without the context path). The server returns no response / closes the connection, and after retries are exhausted a MaxRetryError / RemoteDisconnected is raised.

Root cause

urlparse(self.url).netloc gives only the host. The context path is in .path and is discarded. The fix for #957 resolved the MissingSchema crash but introduced this regression by using scheme://netloc rather than scheme://netloc/context_path.

Expected behaviour

The next-page URL should be resolved as scheme://netloc/context_path/rest/api/....

Fix

Preserve parsed.path when building site_url:

parsed = urlparse(self.url)
site_url = f"{parsed.scheme}://{parsed.netloc}{parsed.path.rstrip('/')}\u200b"
url = f"{site_url}/{next_link.lstrip('/')}\u200b"

The same class of bug affects the Cloud v2 cursor pagination path and was reported in #1655.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions