pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.95k stars 869 forks source link

Authentification failed and returns ERROR Expecting value: line 1 column 1 (char 0) #1340

Open NickKupka opened 2 years ago

NickKupka commented 2 years ago

Bug summary

After an update of the source jira login mechanism we are no longer able to login with your jira tool. The server updated the authentification method including a redirect where we get an "Loading..." page (which returns 200 OK within your tool) where the browser redirects like 0.5 seconds later to the real loginpage.

As fas as we discovered the jira python tool crashes in class "client.py" if get_server_info:

We need version in order to know what API calls are available or not

        si = self.server_info()

because the session does not have an authentification cookie because the authenficiation never happens.

When calling the function

def server_info(self) -> Dict[str, Any]:
    """Get a dict of server information for this Jira instance.

    Returns:
        Dict[str, Any]
    """
    retry = 0
    j = self._get_json("serverInfo")
    while not j and retry < 3:
        self.log.warning(
            "Bug https://jira.atlassian.com/browse/JRA-59676 trying again..."
        )
        retry += 1
        j = self._get_json("serverInfo")
    return j

the _get_json Method breaks at the following point

r_json = json.loads(r.content) except ValueError as e: self.log.error(f"{e}\n{r.text if r else r}")

because the r.content is expected to be a valid json return including the servers information about the jira api server etc.. But since we only get to the "login..." page without the redirect to the real URL we do not have the possibility to asks the servers information.

This page here appears right before the real login page opens up (which is never received by the jira python tool) image

This would be the real login page (which can't be accessed right now - but has to) image

Would be very happy to hear from you,

Is there an existing issue for this?

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

No response

jira-python version

3.1.1

Python Interpreter version

3.8

Which operating systems have you used?

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the function with argument x
jira.the_function(x)
# 3.
...

I guess I have mentioned all relevant information in the bug report including the functions.

Stack trace

Traceback (most recent call last):
  File "D:/workspace/workspace_python_example/jira_sync/main.py", line 125, in LoadConfig
    self.source_jira = JIRA(self.config['source_jira_server'], max_retries=0, basic_auth=(self.config['source_user'], aes.decrypt(self.config['source_password'])))
  File "D:\workspace\workspace_python_example\venv\lib\site-packages\jira\client.py", line 546, in __init__
    si = self.server_info()
  File "D:\workspace\workspace_python_example\venv\lib\site-packages\jira\client.py", line 2883, in server_info
    j = self._get_json("serverInfo")
  File "D:\workspace\workspace_python_example\venv\lib\site-packages\jira\client.py", line 3564, in _get_json
    raise e
  File "D:\workspace\workspace_python_example\venv\lib\site-packages\jira\client.py", line 3561, in _get_json
    r_json = json.loads(r.content)
  File "C:\ProgramData\Miniconda3\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\ProgramData\Miniconda3\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\ProgramData\Miniconda3\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Expected behaviour

That the JIRA Instance can successfully authentificate with username and password and can fetch all the jira data from the server.

It is not able to fetch the following information from the server and crashes because of the new login mechanism including the "Loading..." page which appears for 0.5 seconds and then automatically redirects to the real login page which is never reached by the jira python tool.

{"baseUrl":"https://......./mgujira","version":"7.13.8","versionNumbers":[7,13,8],"deploymentType":"Server","buildNumber":713008,"buildDate":"2019-09-13T00:00:00.000+0200","serverTime":"2022-04-01T13:07:27.929+0200","scmInfo":".......","serverTitle":"............."}

Additional Context

No response

studioj commented 2 years ago

is this authentication/"loading" part of Jira server? or is a sort of "landing" page which is locally implemented with a nginxproxy for example?

NickKupka commented 2 years ago

It is not part of a jira server. Exactly it is a local landing page with nginxproxy.

adehad commented 2 years ago

If this is a static redirect are you able to use the redirected URL with the client?

I think handling the redirect requests might have also popped up in another issue too (#1196), so still worth addressing.

NickKupka commented 2 years ago

Hi, unfortunately this is not a static redirect and we are not able to call the redirected URL.