Skip to content

docker_ requests.exceptions.HTTPError: 404 Client Error #1505

@Kunzol

Description

@Kunzol

I am not really a docker expert, so some of my guesses might not be right.

In the docker_ plugin I got a 404 error while fetching data from the docker installation (see below).

From what I see, it can not get the "tags" from some "container.image". Maybe some of my container images have no tags ?

OS: Debian 12 Bookworm AMD64
Command: munin-run docker_multi config

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 268, in _raise_for_status
    response.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.41/images/3c9486e5486095aa132f1d45508f95c4b5b6a27995ef52e6b24c70c8126be0cb/json

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/etc/munin/plugins/docker_multi", line 604, in <module>
    main()
  File "/etc/munin/plugins/docker_multi", line 597, in main
    globals()[s](client, mode)
  File "/etc/munin/plugins/docker_multi", line 499, in cpu
    print("{}.info {}".format(fieldname, container_attributes(container)))
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/munin/plugins/docker_multi", line 205, in container_attributes
    attributes = container.image.tags
                 ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/models/containers.py", line 40, in image
    return self.client.images.get(image_id.split(':')[1])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/models/images.py", line 314, in get
    return self.prepare_model(self.client.api.inspect_image(name))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/api/image.py", line 251, in inspect_image
    return self._result(
           ^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 274, in _result
    self._raise_for_status(response)
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 270, in _raise_for_status
    raise create_api_error_from_http_exception(e)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.41/images/3c9486e5486095aa132f1d45508f95c4b5b6a27995ef52e6b24c70c8126be0cb/json: Not Found ("no such image: 3c9486e5486095aa132f1d45508f95c4b5b6a27995ef52e6b24c70c8126be0cb: No such image: sha256:3c9486e5486095aa132f1d45508f95c4b5b6a27995ef52e6b24c70c8126be0cb")

For the moment, my simple fix was to catch the exception in the function "container_attributes" (line 204).

def container_attributes(container, *args):
    try: 
        attributes = container.image
        attributes = attributes.tags
        attributes.append(container.attrs['Created'])
        return ', '.join(attributes + list(args))
    except:
        return

I am not a python expert, maybe there is more elegant solution.
At least this removes the error, but currently I am not sure if there are any other side effects I don't see during my first tests.

If it helps, I can create a pull-request on this.

Thanks for reading ...

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