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

REST API and HTTP errors #171

Closed
stanislavlevin opened this issue Oct 21, 2022 · 0 comments · Fixed by #172
Closed

REST API and HTTP errors #171

stanislavlevin opened this issue Oct 21, 2022 · 0 comments · Fixed by #172

Comments

@stanislavlevin
Copy link
Contributor

The following query crashes:

import bugzilla


URL = "bugzilla.stage.redhat.com"
bzapi = bugzilla.Bugzilla(URL, force_rest=True, use_creds=False)
print(bzapi.logged_in)
Traceback (most recent call last):
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_session.py", line 108, in request
    response.raise_for_status()
  File "/usr/lib/python3/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://bugzilla.stage.redhat.com/rest/user?ids=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/test.py", line 6, in <module>
    print(bzapi.logged_in)
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/base.py", line 720, in logged_in
    raise e
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/base.py", line 714, in logged_in
    self._backend.user_get({"ids": [1]})
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_backendrest.py", line 182, in user_get
    return self._get("/user", paramdict)
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_backendrest.py", line 63, in _get
    return self._op("GET", *args, **kwargs)
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_backendrest.py", line 58, in _op
    response = self._bugzillasession.request(method, fullurl, data=data,
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_session.py", line 112, in request
    raise type(e)(message).with_traceback(sys.exc_info()[2])
  File "/usr/src/RPM/BUILD/python-bugzilla/bugzilla/_session.py", line 108, in request
    response.raise_for_status()
  File "/usr/lib/python3/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://bugzilla.stage.redhat.com/rest/user?ids=1

The problem is that logged_in expects BugzillaError or any other exception having code or faultCode attribute.

Bugzilla codes are mapped to HTTP status codes:
https://github.com/bugzilla/bugzilla/blob/7581e08f9136ec32219af6c3192e42ff1c8e9691/Bugzilla/WebService/Constants.pm#L262-L287

But this project don't handle such codes on HTTP errors.

stanislavlevin added a commit to stanislavlevin/python-bugzilla that referenced this issue Oct 21, 2022
Bugzilla REST API map result codes to HTTP status codes:
https://github.com/bugzilla/bugzilla/blob/7581e08f9136ec32219af6c3192e42ff1c8e9691/Bugzilla/WebService/Constants.pm#L262-L287

But python-bugzilla don't propagate those Bugzilla codes.

Fixes: python-bugzilla#171
Signed-off-by: Stanislav Levin <slev@altlinux.org>
crobinso pushed a commit that referenced this issue Aug 20, 2023
Bugzilla REST API map result codes to HTTP status codes:
https://github.com/bugzilla/bugzilla/blob/7581e08f9136ec32219af6c3192e42ff1c8e9691/Bugzilla/WebService/Constants.pm#L262-L287

But python-bugzilla don't propagate those Bugzilla codes.

Fixes: #171
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant