Skip to main content
Navigator | Tier 3
November 17, 2025
Solved

Pass Control Room file (.env) variable to Python function

  • November 17, 2025
  • 11 replies
  • 189 views

Hello Community,


I tested the Python script in Automation Anywhere and it works fine when I run it locally — it loads everything correctly from the .env file using load_dotenv.

Then uploaded the .env file into Control Room and created an input variable called demo_env.

Then I added the wrapper file with the demo_env parameter.
 


 


But whenever I run it from AA, it fails and says there’s an issue in the code — even though it works perfectly when using the local .env path.

Can someone take a look? I’m not sure what’s going wrong here.

 

def aa_wrapper(demo_env, search_terms=None, days=None, use_database=True):
"""AA wrapper with schedule checking"""
start_time = datetime.datetime.now()

try:
logger.info("=== CVE Check AA Wrapper Started ===")
#env_path=r"\Bots\dev_bot\euo\.env"
#env_path=demo_env
# Handle if demo_env is a file object or string
if hasattr(demo_env, 'path'):
env_path = demo_env.path
elif hasattr(demo_env, '__str__'):
env_path = str(demo_env)
else:
env_path = demo_env

path = env_path
#path = env_path or DEFAULT_ENV_PATH

if not os.path.exists(path):
error_msg = f"ERROR: .env file not found at {path}"
logger.error(error_msg)
return error_msg

from dotenv import load_dotenv
load_dotenv(dotenv_path=path, override=True)
logger.info("Environment variables loaded")

error_log_path = os.getenv("CVE_LOG_PATH", "cve_check_error.log")
setup_logging(error_log_path)

should_run, reason = should_run_cve_check()

if not should_run:
logger.info("=== CVE Check Skipped ===")
logger.info(reason)
return f"SKIPPED: {reason}"

terms_list = DEFAULT_SEARCH_TERMS
if search_terms:
terms_list = [term.strip().lower() for term in search_terms.split(',')]
logger.info(f"Using search terms: {terms_list}")

days_to_use = DEFAULT_DAYS
if days:
days_to_use = min(int(days), 120)
logger.info(f"Using days: {days_to_use}")

logger.info("Starting CVE check")
success = main_cve_check(terms_list, days_to_use, True, use_database)

elapsed = (datetime.datetime.now() - start_time).total_seconds()

db_status = " (with database)" if use_database else " (no database)"

if success:
success_msg = f"SUCCESS: CVE check completed in {elapsed:.2f}s{db_status}. {reason}"
logger.info(success_msg)
return success_msg
else:
error_msg = f"FAILED: CVE check failed after {elapsed:.2f}s"
logger.error(error_msg)
return error_msg

except Exception as e:
elapsed = (datetime.datetime.now() - start_time).total_seconds()
error_msg = f"ERROR: {e} after {elapsed:.2f}s"
logger.error(error_msg)
logger.error("Exception:", exc_info=True)
return error_msg

 

    Best answer by Padmakumar

    @Padmakumar 

    Thanks

    You mentioned using Credential → Assign to read DB_User and DB_Pass from the locker and save them into string variables like sDbUser and sDbPass.

    But even after saving them into variables, the variable type still stays as Credential, so we can’t pass it into the function arguments. Since this part doesn’t seem to work on my side, could you send me a screenshot showing how you were able to make it work?

    Well, I am using the below credential package to convert the value to a string. Sorry, I missed mentioning this in my previous response.

    Credential Utilities - Bot Store

     

     

    11 replies

    Padmakumar
    Premier Pathfinder | Tier 7
    Premier Pathfinder | Tier 7
    November 20, 2025

    @Padmakumar 

    Thanks

    You mentioned using Credential → Assign to read DB_User and DB_Pass from the locker and save them into string variables like sDbUser and sDbPass.

    But even after saving them into variables, the variable type still stays as Credential, so we can’t pass it into the function arguments. Since this part doesn’t seem to work on my side, could you send me a screenshot showing how you were able to make it work?

    Well, I am using the below credential package to convert the value to a string. Sorry, I missed mentioning this in my previous response.

    Credential Utilities - Bot Store

     

     

    Padmakumar