Missing required environment variable: RC_API_SECRET_HOST when using Vault

Hi,
I followed an example from Robocorp and I’m pretty sure no error or tipo so far but it’s keeping asking me for : RC_API_SECRET_HOST when I’m starting the robot with the command “rcc run”

I saw RC_API_SECRET_HOST as URL to Robocorp Vault API in the documentation but as I’m in local environment and don’t need to access the cloud or store something in it.

Do I miss something here ?

Thanks for your feedback.

Traceback (most recent call last):
  File "D:\RobotFramework\tasks.py", line 9, in <module>
    secret = Vault().get_secret("credentials")
  File "C:\Users\albel\AppData\Local\robocorp\holotree\5a1fac3c5_9fcd2534\lib\site-packages\RPA\Robocorp\Vault.py", line 556, in get_secret
    return self.adapter.get_secret(secret_name)
  File "C:\Users\albel\AppData\Local\robocorp\holotree\5a1fac3c5_9fcd2534\lib\site-packages\RPA\Robocorp\Vault.py", line 532, in adapter
    self._adapter = self._adapter_factory()
  File "C:\Users\albel\AppData\Local\robocorp\holotree\5a1fac3c5_9fcd2534\lib\site-packages\RPA\Robocorp\Vault.py", line 546, in factory
    return adapter(*args, **kwargs)
  File "C:\Users\albel\AppData\Local\robocorp\holotree\5a1fac3c5_9fcd2534\lib\site-packages\RPA\Robocorp\Vault.py", line 211, in __init__
    self._host = required_env("RC_API_SECRET_HOST")
  File "C:\Users\albel\AppData\Local\robocorp\holotree\5a1fac3c5_9fcd2534\lib\site-packages\RPA\core\helpers.py", line 56, in required_env
    raise KeyError(f"Missing required environment variable: {name}")
KeyError: 'Missing required environment variable: RC_API_SECRET_HOST'

Error: exit status 1
1 Like

You need to set up local vault to use secrets.

Hi,

These were the steps I went through :

  • I created a vault.json file that look like in the tutorial :
  {
  "credentials": {
    "username": <myusername>,
    "password": <mypassword>
  }
 }

and put it in : "C:\\Users\\<myuser>\\vault.json"

then I created the env.json file under devdata folder that looks like this :

{
  "RPA_SECRET_MANAGER": "RPA.Robocorp.Vault.FileSecrets",
  "RPA_SECRET_FILE": "C:\\Users\\<myuser>\\vault.json"
}

And finally, I requested my credential in my tasks.py robot (Actually, I’m using full python implementation instead of robotframework script)

and it looks like this :

from RPA.Browser.Selenium import Selenium
from RPA.Robocorp.Vault import Vault
from robot.api import logger
lib = Selenium()

secret = Vault().get_secret("credentials")
username = secret["username"] 
password = secret["password"]

So, if I understood, all things are there except creating credentials in robocorp cloud. Something that I don’t want to do.

As I’m newbie, maybe there are things I didn’t catch up yet.

@arcondo.dasilva are you running in terminal with rcc run ? If yes, then you need to pass env.json as an argument for rcc

rcc run -e devdata\env.json

The VSCode Robocorp extension includes devdata env.json automatically if it exists, but when running in terminal you need to include env.json

Here’s some more explanation on the topic by @mika.

Using script from command line with rcc

enter command rcc task shell to open shell into environment
enter command use-robocorp-vault set and follow instructions
include devdata/env.json in a command rcc run -e devdata/env.json

Hope this helps!

2 Likes

This is great. It works!
This is my second day with Robot Framework and it’s pretty impressive. I actually used to use UiPath, but things can change quickly.

Thanks, I can now move foreward

4 Likes

Hello, I’ve stuck while creating simple robot please help, I have some overall Python knowledge but I would build Robots using RobocorpLAB, I manage to open the browser & robotsparebin intra page, but I can’t go thrue logon section using logon credentials from local vault (important note - I don’t want to use cloud)
I have container for secrets in C:\Users\<my_user_name>\vault.json\<name_of_jsonFileWithRequestedCredentials>, I have env.json file in local storage C:\Users\<my_user_name>\Robocorp\devdata\env.json (htis is important for me to be as a local authentication), below is a code for the robot - please help, I’m lack of ideas where should I pinpoint robot to use local env.json

*** Settings ***
Documentation Robot that logs into the RobotSparebinIndustries Intranet with passwd
Library RPA.Browser
Library Collections
Library MyLibrary
Library RPA.Robocorp.Vault
Library RPA.JSON
Resource keywords.robot
Variables MyVariables.py
*** Keywords ***
OpenIntranetWebPage
Open Available Browser https://robotsparebinindustries.com/
*** Keywords ***
LogIn
${secret}= Get Secret credentials
Input Text id:username ${secret_name}[Username]
Input Password id:password ${secret}[Password]
Submit Form
Wait Until Page Does Not Contain id:password

*** Tasks ***
Open browser, go to webpage, login using secret passwd
OpenIntranetWebPage
LogIn

Log    Done

Log

Task(s) failed:

Task Open browser, go to webpage, login using secret passwd failed with: KeyError: ‘Missing required environment variable: RC_API_SECRET_HOST’

Have you defined the environment variables that file secrets require in env.json https://robocorp.com/docs/libraries/rpa-framework/rpa-robocorp-vault

this is the env

{
“RPA_SECRET_MANAGER”: “RPA.Robocorp.Vault.FileSecrets”,

"RPA_SECRET_FILE":  "C:\\Users\\limpy\\vault.json\\RobSpareBIN_mariaPass.JSON"

}

and this is the credentials

{
“credentials”: {
“Username”: “maria”,
“Password”: “thoushallnotpass”
}
}

I have installed relevant library

Library RPA.Robocorp.Vault
Library RPA.JSON

but still - I don’t understand how robot itself isd linked with my env file - moreover I’m quite sure that this is the root cause oif my case but can’t find in the documentation where to point-out where is the env file which my robot should use - I imagine that it can’t be “any” env file it has to be exact one - I’ve seen that rcc users have some additional parameter to point-out the env file location, bur as long as I would like to use RobocorpLAB I would like to avoid using alternatives

You state that above is your env.json location. So, is robot then located at that Robocorp folder? Because every robot should have their own devdata\env.json, and no some shared env.json. If you want to use something shared, then you could run it using rcc as Mika has show above, and give (relative or absolute) path to your env.json there.

thanks for reply - No my robot is NOT located in Robocorp folder, how can I find where my robot is located to move there devdata\env.json, from Robocorp folder - I know that question is quite silly, but I guess it’s better to ask a silly question rather not complete the training with 10% knowledge obtained

If you are using Lab, then it is easiest to go into Lab and see it there. So open your robot in lab, and there under “robot root” there should be “devdata” folder, where env.json is located. That is where you should put that configuration data.

And “robot root” is where “robot.yaml” is located. And “devdata” is relatively located to that.

…if you have trouble finding where your robot directory is, that can be seen e.g. in Lab project launcher (the first page when you start lab).

@Teppo - Your reply was the fastest way & the clearest explanation, problem solved - thx once again for help

Hi guys,
I had the same problem and surfing the forum I found the solution here posted.
It works greatly fine
Thanks :slight_smile:

1 Like