Skip to content

REST API and HTTP errors #171

Description

@stanislavlevin

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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