heey everyone, does anybody know how to put more t...
# prefect-ui
l
heey everyone, does anybody know how to put more than one variable in a secret, maybe as json? thanks :)
āœ… 1
j
Hi @Laura Vaida - yes you can use json for your secrets. If you click on the 'Type' button on the bottom right of the secret input box you can choose JSON and that will help you make sure your json is properly formatted.
l
Copy code
{
"host" : "___",
"port" : "___",
"username" : "___,
"password" : "___"
}
Thanks @Jenny, like that for example? :)
j
Looks good. The JSON formatter would pick this up for you but looks like you're missing an " at the end of username. šŸ˜ƒ
l
ah you're right, thanks! do you know how to infer to a specific value from that, e.g. username?
j
You should be able to access it like a python dictionary. E.g.
Copy code
from prefect import task, Flow
from prefect.tasks.secrets import PrefectSecret

@task
def access_secret(secret_value):
    # Access your secret and now you can use it however you would like
    print(secret_value['username'])

with Flow("secret-retrieval") as flow:
    secret = PrefectSecret("MY_SECRET")
    access_secret(secret)

flow.run()
l
thanks, will try that! šŸ™‚
ok, i tried with the following:
Copy code
@task(log_stdout=True)
def create_engine(snowflake_salesforce):
    config = configparser.ConfigParser()
    engine=create_engine(URL(**config[snowflake_salesforce]))
with Flow('UWG-Mail') as flow:
    snowflake_credentials=PrefectSecret("Snowflake_Salesforce")
    connection=create_engine(snowflake_salesforce=snowflake_credentials)
but it's resulting in that error:
Copy code
Unexpected error: TypeError("unhashable type: 'dict'")
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner
    new_state = method(self, state, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 863, in get_task_run_state
    value = prefect.utilities.executors.run_task_with_timeout(
  File "/usr/local/lib/python3.8/site-packages/prefect/utilities/executors.py", line 298, in run_task_with_timeout
    return task.run(*args, **kwargs)  # type: ignore
  File "<input>", line 36, in create_engine
  File "/usr/local/lib/python3.8/configparser.py", line 959, in __getitem__
    if key != self.default_section and not self.has_section(key):
  File "/usr/local/lib/python3.8/configparser.py", line 668, in has_section
    return section in self._sections
TypeError: unhashable type: 'dict'
do you know any help here?
j
Hi Laura - if you have new questions it's best to ask in a new thread. Iā€™m OOO today and other team members might not see this. Generally that error message means you're trying to use a dict as a key in another dict.
l
sure thing, well do so! thank you šŸ™‚
šŸ™‚ 1