diff --git a/doccano_client/repositories/example.py b/doccano_client/repositories/example.py index 30b7e9b..2192295 100644 --- a/doccano_client/repositories/example.py +++ b/doccano_client/repositories/example.py @@ -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 @@ -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