Skip to content

X-Total-Pages header not (always) set #1

Open
@xlemmingx

Description

@xlemmingx

Hey,
thanks for your work! Unfortunately I got an error while trying to use the api wrapper.

Environment

  • listmonk v2.3.0 in docker behind a nginx-reverse proxy with a single list and a single subscriber
  • python script on remote computer using this api in version 0.1.2

Code
lm_client = listmonk_api.Api(url=listmonk_api_url, username=username, password=password) print(f"Subscribers: {lm_client.get_subscribers()}")

Error
Traceback (most recent call last): File "/home/random/repositories/test/files.py", line 22, in <module> print(f"Subscribers: {lm_client.get_subscribers()}") File "/home/random/repositories/test/.venv/lib/python3.10/site-packages/listmonk_api/decorators.py", line 19, in wrapper return function(self, *args, **kwargs) File "/home/random/repositories/test/.venv/lib/python3.10/site-packages/listmonk_api/listmonk_api.py", line 65, in get_subscribers total_pages = int(response.headers['X-Total-Pages']) File "/home/random/repositories/test/.venv/lib/python3.10/site-packages/requests/structures.py", line 52, in __getitem__ return self._store[key.lower()][1] KeyError: 'x-total-pages'

At first I thought it may be caused by the nginx dropping an empty header, but even a local request from inside the container isn't containg an 'X-Total-Pages'-header.

A possible solution could be to fall back to 1 if the header doesn't exist (seems to be the case if the response isn't paged at all?).

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