Hi at all, im trying to use the following function...
# prefect-ui
l
Hi at all, im trying to use the following function:
Copy code
For convenience, you can use the snowflake.sqlalchemy.URL method to construct the connection string and connect to the database. The following example constructs the same connection string from the previous example:

from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    account = 'myorganization-myaccount',
    user = 'testuser1',
    password = '0123456',
    database = 'testdb',
    schema = 'public',
    warehouse = 'testwh',
    role='myrole',
))
I want to create an engine with passing the input for URL with ** instead of putting every variable but I dont know how to write the input, it should be a str format that's what I tried, maybe you have an idea how input data should look like
Copy code
###selecting order data
@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")
    connection=create_engine(snowflake_salesforce=snowflake_credentials)
but resulting in this error
Copy code
[12:03 Uhr] 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'
1
m
where you setup your secret? env or cloud?
l
in the cloud
m
you put json in secret?
Copy code
from prefect.client import Secret
config = Secret("Snowflake").get()

@task(log_stdout=True)
def create_engine(snowflake_cfg):
    engine=create_engine(URL(**snowflake_cfg))
with Flow('UWG-Mail') as flow:
    connection=create_engine(snowflake_salesforce=config)
try something like this
l
thanks! do you know how to format the secrets for that?
m
i think like this
and after Secret("Snowflake").get() you have dict
l
ahh maybe also possible as string?
m
Sure, you can add secret as string. Also you can run
Copy code
from prefect.client import Secret
config = Secret("Snowflake").get()
from local env and saw what do you get
l
can you give an example for the format? i don't get it 😄 sorry
k
Did you get this one @Laura Vaida?
l
yes, solved it, thanks 🙂