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

401 is not a recoverable error #1929

Open
3 of 4 tasks
Poddster opened this issue Dec 3, 2024 · 0 comments
Open
3 of 4 tasks

401 is not a recoverable error #1929

Poddster opened this issue Dec 3, 2024 · 0 comments

Comments

@Poddster
Copy link

Poddster commented Dec 3, 2024

Bug summary

Running a test with incorrect credentials causes this module to re-try 3 times with the incorrect credentials. This is because it considers 401 UNAUTHORIZED as a "recoverable error", which it clearly isn't. The details aren't going to correct themself, or if the credentials are correct then authorisation isn't going to change during this retry process.

Doing this wastes 30 seconds and also makes 3 unauthorised attempts rather than 1

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

1001.0.0-SNAPSHOT

jira-python version

jira==2.0.0

Python Interpreter version

3.9

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

def _run_tests():
        logging.basicConfig(
            level=logging.DEBUG,
            format="gjh_jira.py: %(levelname)s: %(message)s"
        )

        jira_options = {'server': JIRA_URL}

        jira_username = 'EXAMPLE@EXAMPLE.com'
        logging.debug("Jira username: " + jira_username)

        key = "123456789012345678901234"

        jira = JIRA(options=jira_options, basic_auth=(jira_username, key))

        print("before myself")
        myself = jira.myself()
        from pprint import pprint
        pprint(myself)

        return 0


    if __name__ == "__main__":
        import sys

        sys.exit(_run_tests())

Stack trace

example.py: DEBUG: Jira username: USER@EXAMPLE.com
    example.py: DEBUG: Read API key from C:\Users\USER\.jira_api_key_lol
    example.py: DEBUG: Starting new HTTPS connection (1): EXAMPLE.atlassian.net:443
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/serverInfo HTTP/11" 200 None
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/field HTTP/11" 200 None
    before myself
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/myself HTTP/11" 401 53
    example.py: WARNING: Got recoverable error from GET https://EXAMPLE.atlassian.net/rest/api/2/myself, will retry [1/3] in 10.68117764269255s. Err: 401 Unauthorized
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/myself HTTP/11" 401 53
    example.py: WARNING: Got recoverable error from GET https://EXAMPLE.atlassian.net/rest/api/2/myself, will retry [2/3] in 11.97750340599477s. Err: 401 Unauthorized
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/myself HTTP/11" 401 53
    example.py: WARNING: Got recoverable error from GET https://EXAMPLE.atlassian.net/rest/api/2/myself, will retry [3/3] in 35.27067587306497s. Err: 401 Unauthorized
    example.py: DEBUG: https://EXAMPLE.atlassian.net:443 "GET /rest/api/2/myself HTTP/11" 401 53
    Traceback (most recent call last):
      File "C:\dev\env\python\Python39\lib\runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\dev\env\python\Python39\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\dev\work\example\example\example.py", line 223, in <module>
        sys.exit(_run_tests())
      File "C:\dev\work\example\example\example.py", line 200, in _run_tests
        myself = jira.myself()
      File "C:\dev\env\python\Python39\lib\site-packages\jira\client.py", line 2142, in myself
        return self._get_json('myself')
      File "C:\dev\env\python\Python39\lib\site-packages\jira\client.py", line 2549, in _get_json
        r = self._session.get(url, params=params)
      File "C:\dev\env\python\Python39\lib\site-packages\jira\resilientsession.py", line 151, in get
        return self.__verb('GET', url, **kwargs)
      File "C:\dev\env\python\Python39\lib\site-packages\jira\resilientsession.py", line 147, in __verb
        raise_on_error(response, verb=verb, **kwargs)
      File "C:\dev\env\python\Python39\lib\site-packages\jira\resilientsession.py", line 56, in raise_on_error
        raise JIRAError(
    jira.exceptions.JIRAError: JiraError HTTP 401 url: https://EXAMPLE.atlassian.net/rest/api/2/myself
            text: Client must be authenticated to access this resource.

            response headers = {'Date': 'Tue, 03 Dec 2024 10:33:37 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '53', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': '6f699b1176d474074a37545c633042fd', 'X-Seraph-Loginreason': 'AUTHENTICATED_FAILED', 'Cache-Control': 'no-cache, no-store, no-transform', 'Www-Authenticate': 'OAuth realm="https%3A%2F%2FEXAMPLE.atlassian.net"', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': '66a1da223eba43c98eea7508e2cf0a73', 'Atl-Request-Id': '66a1da22-3eba-43c9-8eea-7508e2cf0a73', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Report-To': '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Server-Timing': 'atl-edge;dur=84,atl-edge-internal;dur=10,atl-edge-upstream;dur=74,atl-edge-pop;desc="aws-eu-west-2"'}
            response text = Client must be authenticated to access this resource.

Expected behaviour

I expect it to throw the error on the first attempt

Additional Context

No response

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

No branches or pull requests

1 participant