Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
243 stars 76 forks source link

`nipyapi.canvas.get_root_pg_id()` intermittent failures #315

Closed andyadamides closed 1 year ago

andyadamides commented 1 year ago

I have separate environments of Nifi, but my production environment randomly fails(as in sometimes it works, sometimes it doesn't) when executing nipyapi.canvas.get_root_pg_id(). Other environments are all fine.

Function call:

nipyapi.canvas.get_root_pg_id()

Traceback

File "/usr/lib/python3.7/site-packages/nipyapi/canvas.py", line 44, in get_root_pg_id
    return nipyapi.nifi.FlowApi().get_process_group_status('root') \
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/apis/flow_api.py", line 2833, in get_process_group_status
    (data) = self.get_process_group_status_with_http_info(id, **kwargs)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/apis/flow_api.py", line 2923, in get_process_group_status_with_http_info
    collection_formats=collection_formats)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 334, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 155, in __call_api
    _request_timeout=_request_timeout)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 357 in request
    headers=headers)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/rest.py", line 244, in GET
    query_params=query_params)
  File "/usr/lib/python3.7/site-packages/nipyapi/nifi/rest.py", line 235, in request
    raise ApiException(http_resp=r)
nipyapi.nifi.rest.ApiException: (401)
Reason: Unauthorized
'WWW-Authenticate': 'Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Signed JWT rejected: Another algorithm expected, or no matching key(s) found", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"', 'Server': 'Jetty(9.4.46.v20220331)'}

I can verify that the credentials that I use to authenticate work 100% when not using nipyapi - also as mentioned sometimes it works, sometimes it doesn't.

Any ideas why or how to fix?

andyadamides commented 1 year ago

Ah, turns out, it's because I had used the same credentials (as the process attempting the above)to login from my browser. Once I logged out and tried the process again, it worked.