nipyapi icon indicating copy to clipboard operation
nipyapi copied to clipboard

Random Unable to validate access token errors - Using NiPyAPI behind Load Balanced NiFi

Open metalshanked opened this issue 4 years ago • 1 comments

  • Nipyapi version: 0.14.3
  • NiFi version: 1.11.4
  • NiFi-Registry version:
  • Python version: 3.7
  • Operating System: Windows + Linux

I get random "Unable to validate access token" errors trying to make calls to a K8s managed NiFi instance which has two pods behind a Load Balancer. I understand this could be because the token is only valid on the NiFi pod that generated the token. However, the LB Server configs already have sticky sessions enabled and it works fine when I make "RAW" requests calls using s=requests.Session() and use the session "s" in subsequent calls.

However, as soon as i use the NiPyAPI library, it works often but often will throw "Unable to validate" access token errors. Is there a way to set the session to be consistent across calls in the NiPyAPI library just like I was able to do with the "RAW" requests library?

Here is what i tried with NiPyAPI.

import nipyapi
def login(instance,username,password):
    if 'registry' in str(instance).lower():
        service_type='registry'
        nipyapi.config.registry_config.verify_ssl = False
    else:
        service_type='nifi' 
        nipyapi.config.nifi_config.verify_ssl = False
        
    nipyapi.utils.set_endpoint(instance)
    nipyapi.utils.wait_to_complete(
                 test_function=nipyapi.utils.is_endpoint_up,
                endpoint_url='-'.join(instance.split('-')[:-1]),
                 nipyapi_delay= nipyapi.config.long_retry_delay,
                nipyapi_max_wait= nipyapi.config.long_max_wait
         )

    nipyapi.security.service_login(service=service_type, username=username, password=password, bool_response=False, auth_type='token') #login
    status = nipyapi.security.get_service_access_status(service=service_type)
    return status


login(nifi,username,password)
rootPgId = nipyapi.canvas.get_root_pg_id()
rootPg = nipyapi.canvas.get_process_group(rootPgId, identifier_type='id')

metalshanked avatar Jul 15 '20 20:07 metalshanked

Really interesting situation to look into and resolve, I think @kevdoran might also be interested.

Chaffelson avatar Jul 16 '20 15:07 Chaffelson

@metalshanked did you fixed this issue somehow?

janis-ax avatar Mar 07 '23 17:03 janis-ax