Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use client base url in example pagination #162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doccano_client/repositories/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Iterator, List, Optional
from urllib.parse import urlparse

from doccano_client.models.example import Example
from doccano_client.repositories.base import BaseRepository
Expand Down Expand Up @@ -60,7 +61,15 @@ def list(self, project_id: int, is_confirmed: Optional[bool] = None) -> Iterator
if examples["next"] is None:
break
else:
response = self._client.get(examples["next"])
next_url = examples["next"]
response = self._client.get(next_url)
# If the response we got is not json parseable, most likely the hostname was set wrongly.
# This can happen if doccano is hosted behind a reverse proxy. Thus, we use the client's
# base url
if not response.headers.get('content-type') == 'application/json':
client_url_parsed = urlparse(self._client._base_url)
next_url = urlparse(examples["next"])._replace(scheme=client_url_parsed.scheme, netloc=client_url_parsed.netloc).geturl()
response = self._client.get(next_url)

def create(self, project_id: int, example: Example) -> Example:
"""Create a new example
Expand Down