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

404 API Error is not handled properly #3151

Closed
mndeveci opened this issue Jul 4, 2023 · 2 comments
Closed

404 API Error is not handled properly #3151

mndeveci opened this issue Jul 4, 2023 · 2 comments

Comments

@mndeveci
Copy link
Contributor

mndeveci commented Jul 4, 2023

Hi there,

We recently upgraded dockerpy version to 6.2, and we found out an issue when we try to make a call to a non-existent API.

Before this upgrade, we used to get docker.errors.NotFound error with following details;

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    main()
  File "test.py", line 5, in main
    registry_data = docker_client.images.get_registry_data("docker/hello-world")
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/models/images.py", line 337, in get_registry_data
    attrs=self.client.api.inspect_distribution(name, auth_config),
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/utils/decorators.py", line 34, in wrapper
    return f(self, *args, **kwargs)
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/api/image.py", line 281, in inspect_distribution
    return self._result(
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/api/client.py", line 267, in _result
    self._raise_for_status(response)
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/api/client.py", line 263, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/private/tmp/docker-test/.venv420/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.NotFound: 404 Client Error: Not Found ("b'Not Found'")

After upgrade, we are now getting this error Error: a bytes-like object is required, not 'str', which is raised during error handling/generation inside dockerpy library;

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    main()
  File "test.py", line 5, in main
    registry_data = docker_client.images.get_registry_data("docker/hello-world")
   File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/models/images.py", line 356, in get_registry_data
    attrs=self.client.api.inspect_distribution(name, auth_config),
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/utils/decorators.py", line 34, in wrapper
    return f(self, *args, **kwargs)
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/api/image.py", line 287, in inspect_distribution
    return self._result(
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result
    self._raise_for_status(response)
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
    raise create_api_error_from_http_exception(e) from e
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/errors.py", line 34, in create_api_error_from_http_exception
    if any(fragment in explanation_msg
  File "/private/tmp/docker-test/.venv610/lib/python3.8/site-packages/docker/errors.py", line 34, in <genexpr>
    if any(fragment in explanation_msg
Error: a bytes-like object is required, not 'str'

I think error originates from here https://github.com/docker/docker-py/blob/main/docker/errors.py#L30, since response.content was a string type before, now it is bytes. In order to fix the issue, you might need to change that line to response.text so that it will return a string.

Happy to raise a PR if you are willing to review it.

Thanks!

@milas
Copy link
Contributor

milas commented Nov 21, 2023

Fixed by #3156

@milas milas closed this as completed Nov 21, 2023
@mndeveci
Copy link
Contributor Author

Thanks for the update @milas when do you folks planning to make a new release? we've been waiting for this fix for sometime now.

unkcpz pushed a commit to aiidalab/aiidalab-launch that referenced this issue Jan 24, 2024
Main goal here is to upgrade to docker-py==7.0.0 which contains a bugfix that I ran into while testing locally with Python 3.12:
docker/docker-py#3151

Looks like the bug was introduced in version 6.1.2 which we bumped to in #194 but did not release yet so no users should be affected.

This commit also include remove the duplicate CI job `pre-commit`, since we already use `pre-commit.ci` hook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants